****************************************************************************************************
* PROGRAM OVERVIEW
****************************************************************************************************
*
* PROGRAM: baseline_driver.sas
* Created (mm/dd/yyyy): 11/30/2020
*
*--------------------------------------------------------------------------------------------------
* PURPOSE: This macro drives the creation of L1 and L2 baseline tables (Table 1s)
*
* Program inputs:
*
*
* Program outputs:
*
* PARAMETERS:
*
* Programming Notes:
*
*
*--------------------------------------------------------------------------------------------------
* CONTACT INFO:
* Sentinel Coordinating Center
* info@sentinelsystem.org
*
***************************************************************************************************;
%macro baseline_driver();
%put =====> MACRO CALLED: baseline_driver;
%isdata(dataset=input.&baselinefile.);
%if %eval(&nobs.>0) %then %do;
/* Type 6 baseline tables contain 1 row per switch and these switches need to be included in all 'by' processing*/
%if %str("&reporttype") = %str("T6") %then %do;
%let Switch_s = switchstep;
%end;
%else %do;
%let Switch_s = ;
%end;
***********************************************************************************************;
* Create modified baseline dataset with COHORT and MERGEVAR vars to feed into %baseline_aggregate
***********************************************************************************************;
%macro assign_cohort_mergevar(cohort=, mergevar=, outdata=, crosscheckfile = , crosscheckvar = ,includenonpregnant=N);
data &outdata.;
set input.&baselinefile.;
format cohort mergevar $15. analysisgrp $40. unique_psestimate 3.;
group=lowcase(group);
analysisgrp = group;
runid=lowcase(runid);
cohort = "&cohort";
mergevar = "&mergevar";
unique_psestimate = 1;
run;
/* Identify unique psestimategrp for L2 reports */
%if %sysfunc(index(&reporttype.,L2)) > 0 %then %do;
proc sql noprint;
create table &outdata._ps as
select base.*
,pscs.psestimategrp
from &outdata. as base
left join pscs_masterinputs (where = (covarnum = 0)) as pscs
on base.runid = pscs.runid
and base.analysisgrp = pscs.analysisgrp
order by runid, psestimategrp, order;
quit;
data &outdata.;
set &outdata._ps (drop = unique_psestimate); /* Remove default value */
length unique_psestimate 3;
retain unique_psestimate;
by runid psestimategrp order;
unique_psestimate +1;
if missing(psestimategrp) or first.psestimategrp then unique_psestimate = 1;
run;
proc sort data = &outdata.;
by order;
run;
%end;
/*Only keep rows where group found in selected input file*/
%if %str("&crosscheckfile") ne %str("") %then %do;
/*dummy _crosscheck file*/
data _crosscheck;