****************************************************************************************************
****************************************************************************************************
* PROGRAM: baseline_profile_createdata.sas
* Created (mm/dd/yyyy): 04/16/2021
*--------------------------------------------------------------------------------------------------
* Compute aggregate covariate profile table(s)
*--------------------------------------------------------------------------------------------------
* Sentinel Coordinating Center
* info@sentinelsystem.org
*--------------------------------------------------------------------------------------------------
* Version Date Initials Comment (reference external documentation when available)
* ------- -------- -------- ----------------------------------------------------------------
***************************************************************************************************;
%macro baseline_profile_createdata;
/* Aggregate all potential profile datasets */
%do periodid = %eval(&look_start.) %to %eval(&look_end.);
%do dps = 1 %to %eval(&num_dp.);
%let dpsiteid = %scan(&random_dplist., &dps.);
%let maskedID = %scan(&masked_dplist, &dps);
%if &reporttype = T6 %then %do;
proc sql noprint undo_policy=none;
create table baselinefile_profile_&dps._&periodid. as
inner join alldptable1_&periodid.(where=(metvar = 'PATIENT' and exp_mean&dps > 0)) b
on a.analysisgrp = b.analysisgrp;
data baselinefile_profile_&dps._&periodid;
data _temp_profile_tablenames;
set baselinefile_profile_&dps._&periodid;
if not missing(profilecovarstoinclude);
length profiletablename $40.;
if missing(cohort) then profiletablename = lowcase(cats("&dpsiteid..",runid, "_profile_&periodid"));
else if cohort = 'switch' then profiletablename = lowcase(cats("&dpsiteid..",runid, "_profile_", cohort, "_", switchstep, "_&periodid"));
else profiletablename = lowcase(cats("&dpsiteid..",runid, "_profile_", cohort, "_&periodid"));
select distinct profiletablename into: profiletables separated by ' '
from _temp_profile_tablenames;
select count(distinct profiletablename) into: num_unique_profile_tables
from _temp_profile_tablenames;
%put Extracting profile tables: &profiletables.;
/*Loop through each baseline table, import, stack groups*/
%do b = 1 %to %eval(&num_unique_profile_tables.);
%let profiletable = %scan(&profiletables., &b., ' ');
/*Merge table with GROUPSTABLE and only keep Groups/Analysisgrps in the input file*/
data _temp_profile_tablenames&dps._&b.;
set _temp_profile_tablenames(where=(profiletablename="&profiletable."));
call symputx('mergevar', mergevar);
create table _temp_profile_tablenum&dps._&b. as