****************************************************************************************************
****************************************************************************************************
* PROGRAM: aggregate_l2_datasets.sas
* Created (mm/dd/yyyy): 02/03/2021
*--------------------------------------------------------------------------------------------------
* This macro aggregates L2 MSOC datasets from each DP into one dataset;
* - infile = the name of the file to aggregate across DPs
* - outfile = the name of the final file
* - pscsfile = QRP input file that defines analysis
* - whereclause = condition to restrict infile
* - convrule = comma or space delimited list of indicator numbers to consider model having converged
* - convdata = dataset that contains convergence status (QRP [runid]_estimates_[periodid])
* - settomissvars = comma delimited variables to set to missing if model does not converge
* - renameclause = optional rename statement when reading in dataset
* - a dataset &outfile. containing DP data with DP indentification variable
*--------------------------------------------------------------------------------------------------
* Sentinel Coordinating Center
* info@sentinelsystem.org
***************************************************************************************************;
%macro aggregate_l2_datasets(infile=,
%put =====> MACRO CALLED: aggregate_l2_datasets;
%if &outfile ^= aggwd and %index(&infile.,varinfo) = 0 %then %do;
proc datasets library = work nolist nowarn;
%do dps = 1 %to %eval(&num_dp.);
%let dpidsiteid = %scan(&random_dplist,&dps);
%let maskedID = %scan(&masked_dplist,&dps);
*Manage convergence status - if model did not meet convergence status, then set variables list in
SETTOMISSVARS to missing;
%if %length(&convrule.)>0 %then %do;
%if &pscsfile. = psmatchfile | &pscsfile. = stratificationfile | &pscsfile. = iptwfile %then %do;
%if %sysfunc(exist(&dpidsiteid..&convdata))=1 %then %do;