****************************************************************************************************
****************************************************************************************************
* PROGRAM: baseline_profile_output.sas
* Created (mm/dd/yyyy): 04/29/2021
*--------------------------------------------------------------------------------------------------
* Transform and output covariate profile tables
*--------------------------------------------------------------------------------------------------
* Sentinel Coordinating Center
* info@sentinelsystem.org
*--------------------------------------------------------------------------------------------------
* Version Date Initials Comment (reference external documentation when available)
* ------- -------- -------- ----------------------------------------------------------------
***************************************************************************************************;
%macro baseline_profile_output;
/* Reset table letter at top of dataset loop */
%do periodid = %eval(&look_start.) %to %eval(&look_end.);
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
where not missing(profilecovarstoinclude))
%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));
if cohort = 'mi' then group2=scan(group,1,'_');
if cohort = 'switch' then switchlabel=' ';
call symputx('runid',runid);
%let profileswitches = 0;
%if &reporttype = T6 %then %do;
select max(switchstep) into :profileswitches
from _temp_agg_order_profile;
/* Only loop when there are observations */
%isdata(dataset=_temp_agg_order_profile);
/* Additional loop for profile switching */
%do s = 0 %to &profileswitches;
%if &reporttype = T6 %then %do;
set _temp_agg_order_profile (where=(switchstep = &s));
/* 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
inner join infolder.&&&runid._treatmentpathways b
on a.group = b.analysisgrp and a.switchstep = b.switchevalstep;