****************************************************************************************************
****************************************************************************************************
* PROGRAM: l2_psdistribution_createdata.sas
* Created (mm/dd/yyyy): 03/17/2021
*--------------------------------------------------------------------------------------------------
* PURPOSE: The macro creates both aggregated and DP specific PS distribution datasets
*--------------------------------------------------------------------------------------------------
* Sentinel Coordinating Center
* info@sentinelsystem.org
***************************************************************************************************;
%macro l2_psdistribution_createdata;
%do loopcount = 1 %to &numl2comparisons.;
/*Initialize macro variables for the analysisgrp loop*/
%let OutputPSDistribution = ;
/*set parameters from l2comparisonfile for this loop*/
set l2comparisonfile(where=(order=&loopcount.));
call symputx('runid', runid);
call symputx('analysisgrp', analysisgrp);
call symputx('OutputPSDistribution', OutputPSDistribution);
%if &OutputPSDistribution.=Y %then %do;
/* only psmatchfile, stratificationfile, and iptwfile have histogram */
select strip(file) into: psfile
where analysisgrp = "&analysisgrp.";
%put now computing PS distributions for &analysisgrp.;
%if &psfile. = psmatchfile | &psfile. = stratificationfile | &psfile. = iptwfile %then %do;
set pscs_masterinputs (where=(lowcase(analysisgrp)="&analysisgrp."));
call symputx("psestimategrp", lowcase(psestimategrp));
%if &psfile. = psmatchfile %then %do;
call symputx('RATIO',upcase(ratio)) ;
%if &psfile. = stratificationfile %then %do;
call symputx("strataweight",strataweight);
set psest_masterinputs (where=(psestimategrp="&psestimategrp."));
call symputx('eoi', eoi) ;
call symputx('ref', ref) ;
%if &psfile. = psmatchfile | &psfile. = stratificationfile | &psfile. = iptwfile %then %do;
/* Determine weights on input dataset to use for squaring */
select count(distinct(weight)) into: numweights trimmed
from agg_psdistribution_&periodid. (where=(runid="&runid." and lowcase(analysisgrp)="&analysisgrp."));
select distinct(weight) into: weight1 - :weight&numweights.
from agg_psdistribution_&periodid. (where=(runid="&runid." and lowcase(analysisgrp)="&analysisgrp."));
%let start = &start. + 0.025;