****************************************************************************************************
* PROGRAM OVERVIEW
****************************************************************************************************
*
* PROGRAM: baseline_profile_output.sas
* Created (mm/dd/yyyy): 04/29/2021
*
*--------------------------------------------------------------------------------------------------
* PURPOSE:
* Transform and output covariate profile tables
*
* Program inputs:
* -
*
* Program outputs:
*
* PARAMETERS:
*
* Programming Notes:
*
*
*--------------------------------------------------------------------------------------------------
* CONTACT INFO:
* Sentinel Coordinating Center
* info@sentinelsystem.org
*
*--------------------------------------------------------------------------------------------------
* CHANGE LOG:
*
* Version Date Initials Comment (reference external documentation when available)
* ------- -------- -------- ----------------------------------------------------------------
*
***************************************************************************************************;
%macro baseline_profile_output;
/* Reset table letter at top of dataset loop */
%let tablecount = 1;
%do periodid = %eval(&look_start.) %to %eval(&look_end.);
proc sql noprint ;
select 'order='||strip(put(order,8.))||' and runid='||quote(strip(runid))||' and group='||quote(strip(group))||' and cohort='||quote(strip(cohort))||' and baselinegroupnum='||put(baselinegroupnum,8.)
into :whereexpr separated by '@'
from (select order, runid, group, case when(cohort is missing) then 'all' else cohort end as cohort, baselinegroupnum
from baselinefile
where not missing(profilecovarstoinclude))
order by order;
quit;
%do wherenum = 1 %to %sysfunc(countw(&whereexpr, @));
%let where = %scan(&whereexpr,&wherenum, @);
data _temp_agg_order_profile;
set aggregate_profile(where=(periodid=&periodid and &where));
grouplabel='';
if cohort = 'mi' then group2=scan(group,1,'_');
else group2=group;
if cohort = 'switch' then switchlabel=' ';
call symputx('runid',runid);
run;
%let profileswitches = 0;
%if &reporttype = T6 %then %do;
proc sql noprint;
select max(switchstep) into :profileswitches
from _temp_agg_order_profile;
quit;
%end;
/* Only loop when there are observations */
%isdata(dataset=_temp_agg_order_profile);
%if &nobs > 0 %then %do;
/* Additional loop for profile switching */
%do s = 0 %to &profileswitches;
%if &reporttype = T6 %then %do;
data _temp_agg_profile;
set _temp_agg_order_profile (where=(switchstep = &s));
run;
/* Join treatment file onto profile table to obtain product group */
proc sql noprint undo_policy=none;
create table _temp_agg_profile as
select a.*, b.group as productswitchgroup
from _temp_agg_profile a
inner join infolder.&&&runid._treatmentpathways b
on a.group = b.analysisgrp and a.switchstep = b.switchevalstep;
quit;
%end;