**************************************************************************************************** * PROGRAM OVERVIEW **************************************************************************************************** * * PROGRAM: ms_createpov4.sas * * Created (mm/dd/yyyy): 02/02/2017 * Last modified: 07/22/2017 * Version: 1.1 * *-------------------------------------------------------------------------------------------------- * PURPOSE: * This program will create the exposure episodes * * Program inputs: * -Dataset with potential index dates (POV1) * -Dataset with claims defined as being potential index dates * * Program outputs: * -Dataset with exposure episodes (POV4) * * PARAMETERS: * -CohortId = Identifier for the cohort being processed (primary, secondary) * * Programming Notes: * * * *-------------------------------------------------------------------------------------------------- * CONTACT INFO: * Mini-Sentinel Coordinating Center * info@mini-sentinel.org * *-------------------------------------------------------------------------------------------------- * CHANGE LOG: * * Version Date Initials Comment (reference external documentation when available) * ------- -------- -------- --------------------------------------------------------------- * 1.1 07/22/17 AP Added Type 5 analysis * ***************************************************************************************************; %macro ms_createpov4(CohortId=); %put =====> MACRO CALLED: ms_createpov4 v1.0; %let paramsuffix=; %if %str("&CohortId.") ne %str("") %then %do; %let paramsuffix=2; %end; %IF %EVAL(&TYPE.=1) %THEN %DO; *Create itt episodes; data _POV4; set _POV1; by Patid; if first.PatId then Episode=0; Episode=Episode+1; *Trick Adate and ExpireDt to mimic an episode and type2 structure; length EpisodeStartDt EpisodeEndDt 4.; format EpisodeStartDt EpisodeEndDt date9.; EpisodeStartDt=Adate; *placeholder; EpisodeEndDt=min(ExpireDt, Enr_end); retain Episode; run; *Create empty IOT file along with empty type2 variables; data _IOT; set _POV4(obs=0); length TrunkDate 4.; TrunkDate=.; T2FupWashPer=.; minepisdur=.; maxepisdur=.; mindaysupp=.; T2CohortDef=" "; keep PatId EpisodeStartDt TrunkDate T2FupWashPer minepisdur maxepisdur mindaysupp T2CohortDef; run; %END; %ELSE %IF %EVAL(&TYPE. ne 3) %THEN %DO; *Create itt episodes; %IF %EVAL(&&ITT¶msuffix.>=1) %THEN %DO; proc sort data=_POV1&CohortId. out=_POV4&CohortId.; by Patid Adate; run; data _POV4&CohortId.; set _POV4&CohortId.; by PatId ADate; if first.PatId then Episode=0; Episode=Episode+1; Expiredt=Adate+&&ittdays¶msuffix.-1; retain Episode; run; %END; %ELSE %DO; *Create claim based episodes (as-treated); %ms_createclaimepi(infile=_GroupIndex&CohortId., gaptype = EpisodeGapType¶msuffix., gap=episodegap¶msuffix., outfile=_POV4&CohortId.); %END; *Summarize episode level details; proc means data=_POV4&CohortId. nway noprint missing; var Adate ExpireDt; class PatId Episode; output out=_POV4&CohortId.(drop=_:) min(Adate)=EpisodeStartDt max(ExpireDt)=EpisodeEndDt/KEEPLEN; run; *Adjust EpisodeEndDt for episode Extension that overlap the next episode; *Will not impact itt; data _NextEpisodeStart&CohortId.; set _POV4&CohortId.; Episode=Episode-1; format NextEpisodeStartDt date9.; NextEpisodeStartDt=EpisodeStartDt; keep PatId Episode NextEpisodeStartDt; run; data _POV4&CohortId.; merge _POV4&CohortId.(in=a) _NextEpisodeStart&CohortId.; by PatId Episode; if _N_=1 then set _CohortDef(keep=expextper¶msuffix.); if a; EpisodeEndDt=sum(EpisodeEndDt,expextper¶msuffix.); if &&itt¶msuffix.=0 and NextEpisodeStartDt and EpisodeEndDt >= NextEpisodeStartDt then EpisodeEndDt = NextEpisodeStartDt - 1; if EpisodeEndDt and EpisodeEndDt