%assign_cohort_mergevar(cohort=preg, mergevar=group, outdata=baselinefile_1, crosscheckfile = cohortfile, crosscheckvar=cohortgrp, includenonpregnant=Y);
****************************************************************************************************
****************************************************************************************************
* 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)
*--------------------------------------------------------------------------------------------------
* 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;
***********************************************************************************************;
* 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);
set input.&baselinefile.;
format cohort mergevar $15. analysisgrp $40. unique_psestimate 3.;
/* Identify unique psestimategrp for L2 reports */
%if %sysfunc(index(&reporttype.,L2)) > 0 %then %do;
create table &outdata._ps as
left join pscs_masterinputs (where = (missing(subgroup))) as pscs
on base.runid = pscs.runid
and base.analysisgrp = pscs.analysisgrp
order by runid, psestimategrp, order;
set &outdata._ps (drop = unique_psestimate); /* Remove default value */
length unique_psestimate 3;
retain unique_psestimate;
by runid psestimategrp order;
if missing(psestimategrp) or first.psestimategrp then unique_psestimate = 1;
proc sort data = &outdata.;
/*Only keep rows where group found in selected input file*/
%if %str("&crosscheckfile") ne %str("") %then %do;
/*dummy _crosscheck file*/