****************************************************************************************************
****************************************************************************************************
* PROGRAM: attrition_createdata.sas
* Created (mm/dd/yyyy): 05/13/2021
*--------------------------------------------------------------------------------------------------
* PURPOSE: This macro transforms and manipulates attrition table data to be output
* - agg_adjusted_attrition
* - agg_patient_attrition
* - agg_episode_attrition
*--------------------------------------------------------------------------------------------------
* 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);
%isdata(dataset=master_inclusioncodes);
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;
%if &t2addonnobs > 0 %then %do;
left join master_t2addon b
on a.group = b.group and a.runid = b.runid
%if &milnobs > 0 %then %do;
on a.group = b.group and a.runid = b.runid
/* Link EOI/REF groups back to analysisgrps */
%if %index(&reporttype,T2L2) %then %do;
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 (where = (missing(subgroup))) a
on a.psestimategrp = b.psestimategrp);
/* Transpose data to have runid, group and groupname structure */
dcl hash attr(multidata:'y') ;
attr.definekey("analysisgrp") ;
attr.definedata("runid","group") ;
/* For L2 requests, cohort groups and analysisgrp values are concatenated with @ delimiter. */
/* Length needs to be increased to accomodate this */
if lr then attr.output(dataset:"_tempgrps");