****************************************************************************************************
* PROGRAM OVERVIEW
****************************************************************************************************
*
* PROGRAM: aggregate_l2_datasets.sas
* Created (mm/dd/yyyy): 02/03/2021
*
*--------------------------------------------------------------------------------------------------
* PURPOSE:
* This macro aggregates L2 MSOC datasets from each DP into one dataset;
*
* Program inputs:
* - 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
*
* Program outputs:
* - a dataset &outfile. containing DP data with DP indentification variable
*
* Programming Notes:
*
*
*--------------------------------------------------------------------------------------------------
* CONTACT INFO:
* Sentinel Coordinating Center
* info@sentinelsystem.org
*
***************************************************************************************************;
%macro aggregate_l2_datasets(infile=,
outfile=,
pscsfile=,
whereclause=,
convrule=,
convdata=,
settomissvars=,
renameclause=,
runidvar=);
%put =====> MACRO CALLED: aggregate_l2_datasets;
%if &outfile ^= aggwd and %index(&infile.,varinfo) = 0 %then %do;
proc datasets library = work nolist nowarn;
delete &outfile.;
quit;
%end;
%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;
%let convergeclause = ;
%let converge = 1;
%if %length(&convrule.)>0 %then %do;
%if &pscsfile. = psmatchfile | &pscsfile. = stratificationfile | &pscsfile. = iptwfile %then %do;
%if %sysfunc(exist(&dpidsiteid..&convdata))=1 %then %do;
data _non_converged_models;
set &dpidsiteid..&convdata.(where=(lowcase(psestimategrp)="&psestimategrp" | lowcase(analysisgrp) = "&analysisgrp"));
if status not in(%quote(&convrule.)) then do;
call symputx('converge', 0);
output;
end;
run;
%isdata(dataset=_non_converged_models);
%if %eval(&nobs.>0) %then %do;
/*build if clause*/
%do bc = 1 %to &nobs.;
data _null_;
set _non_converged_models(keep=subgroup subgroupcat);
if _n_ = &bc. then do;
call symputx('estimatessubgroup', subgroup);
call symputx('estimatessubgroupcat', subgroupcat);
if &bc. >1 then call symputx('orclause', 'or');
else call symputx('orclause', '');
end;
run;
%let convergeclause = &convergeclause. &orclause. (subgroup = "&estimatessubgroup" and subgroupcat = "&estimatessubgroupcat.");
%end;
%end;
proc datasets nowarn noprint lib=work;
delete _non_converged_models;
quit;