****************************************************************************************************
* PROGRAM OVERVIEW
****************************************************************************************************
*
* PROGRAM: attrition_createdata.sas
* Created (mm/dd/yyyy): 05/13/2021
*
*--------------------------------------------------------------------------------------------------
* PURPOSE: This macro transforms and manipulates attrition table data to be output
*
* Program inputs:
* - agg_attrition
* - agg_mil_attrition
* - agg_adjusted_attrition
*
* Program outputs:
* - agg_patient_attrition
* - agg_episode_attrition
*
*
* PARAMETERS:
*
* Programming Notes:
*
*
*--------------------------------------------------------------------------------------------------
* CONTACT INFO:
* Sentinel Coordinating Center
* info@sentinelsystem.org
*
***************************************************************************************************;
%macro attrition_createdata;
/* Link all required groups from inputfiles */
%isdata(dataset=master_t2addon)
%let t2addonnobs = &nobs;
%isdata(dataset=master_mil);
%let milnobs=&nobs;
%isdata(dataset=master_inclusioncodes);
%let inclnobs = &nobs;
proc sql noprint;
create table attrition_groups as
select distinct a.runid, a.group
%if &t2addonnobs > 0 %then %do; , b.primary, b.secondary %end;
%if &milnobs > 0 %then %do; ,b.groupname %end;
from inputfiles a
%if &t2addonnobs > 0 %then %do;
left join master_t2addon b
on a.group = b.group and a.runid = b.runid
%end;
%if &milnobs > 0 %then %do;
left join master_mil b
on a.group = b.group and a.runid = b.runid
%end;
%if %sysfunc(exist(work.l2comparisonfile)) %then %do;
left join l2comparisonfile c
on a.group = c.analysisgrp and a.runid = c.runid
%end;
;
quit;
/* Link EOI/REF groups back to analysisgrps */
%if %index(&reporttype,T2L2) %then %do;
proc sql noprint;
create table _whatgroups as
select distinct runid, analysisgrp, case when missing(eoi) then eoi2 else eoi end as eoi,
case when missing(ref) then ref2 else ref end as ref
from (select a.runid, a.analysisgrp, a.eoi, a.ref, b.eoi as eoi2, b.ref as ref2
from pscs_masterinputs a
left join
psest_masterinputs b
on a.psestimategrp = b.psestimategrp);
quit;
/* Transpose data to have runid, group and groupname structure */
data _null_;
if _n_=1 then do;
dcl hash attr(multidata:'y') ;
attr.definekey("analysisgrp") ;
attr.definedata("runid","group") ;
attr.definedone() ;
end;
/* For L2 requests, cohort groups and analysisgrp values are concatenated with @ delimiter. */
/* Length needs to be increased to accomodate this */
length group $81;
set _whatgroups end=lr;
array t eoi ref;
do over t;