**************************************************************************************************** * PROGRAM OVERVIEW **************************************************************************************************** * * PROGRAM: ms_createt5episodes.sas * * Created (mm/dd/yyyy): 06/27/2017 * Last modified: * Version: 1.0 * *-------------------------------------------------------------------------------------------------- * PURPOSE: * This program will create episodes that occur after a selected index date. * * Program inputs: * -Dataset with claims defined as being potential index dates * -Dataset with valid index date * * Program outputs: * -Dataset with all episodes * * PARAMETERS: * * Programming Notes: * * * *-------------------------------------------------------------------------------------------------- * CONTACT INFO: * Mini-Sentinel Coordinating Center * info@mini-sentinel.org * *-------------------------------------------------------------------------------------------------- * CHANGE LOG: * * Version Date Initials Comment (reference external documentation when available) * ------- -------- -------- --------------------------------------------------------------- * ***************************************************************************************************; %macro ms_createt5episodes(); %put =====> MACRO CALLED: ms_createt5episodes v1.0; data _PtsMasterList; set _PtsMasterList; by patid indexdt; if T5CohortDef ='04' then do; if first.PatId; end; run; /*Select claims on or after index date*/ data _groupindex2(drop=indexdt); length indexdt 8.; if _n_ = 1 then do; declare hash indx(dataset:'_PtsMasterList'); indx.definekey('patid'); indx.definedata('indexdt'); call missing(indexdt); indx.definedone(); end; set _GroupIndex; if indx.find()=0 then do; if adate >= indexdt then output; end; %if %eval (&itt. > 0) %then %do; drop BIRTH_DATE SEX RACE HISPANIC ZIP zip_date IndexDtLookEndDt IndexLook EnrEpisodeCensoredAtDeath DeathDt enr_end_equal_death; %end; run; /*POV1*/ %ms_createpov1(CohortId=2); /*POV4*/ %DoITTCheck(CohortId=2); %ms_createpov4(CohortId=2); /*Create Episode list*/ data _PtsMasterList2; format IndexDt EpisodeEndDt ENR_START ENR_END date9.; merge _POV12(in=pov1 rename=Adate=IndexDt) _POV42(in=pov4 rename=EpisodeStartDt=IndexDt) _IOT2(in=iot rename=EpisodeStartDt=IndexDt); by Patid IndexDt; * Adate represents potential Index Date; if pov1 and pov4; *Index Date must overlap greater monitoring period; if &startfollowup. <= IndexDt <= &enddate.; OrigEpisEndDt = EpisodeEndDt; *Adjust EpisodeEndDt if EpisodeEndDt > enddate; %if &censor_qryend = 1 %then %do; if EpisodeEndDt > &enddate. then EpisodeEndDt = &enddate.; %end; /*Adjust EpisodeEndDt if EpisodeEndDt > DeathDt*/ if EnrEpisodeCensoredAtDeath = 1 and EpisodeEndDt > DeathDt then EpisodeEnddt = deathdt; *Trucate episode at IOT; *Only adjust for IOT when IOT prior to EpisodeEndDate. IOT after EpisodeEndDt can occur if Epiosde shortened to occur on EndDate; if iot and TrunkDate and trunkdate <= EpisodeEndDt then EpisodeEndDt=TrunkDate; *ExpExtPer may have made the episode to go beyond elig.; if EpisodeEndDt > enr_end then EpisodeEndDt = enr_end; *Maximum Episode Duration; if not missing(maxepisdur) and EpisodeEndDt-IndexDt + 1 > maxepisdur then EpisodeEndDt = IndexDt + maxepisdur -1; *Defensive coding; if IndexDt > EpisodeEndDt then delete; keep PatID IndexDt EpisodeEndDt ENR_START ENR_END IndexLook RxSup RxAmt NumDispensing OrigEpisEndDt trunkdate EnrEpisodeCensoredAtDeath Deathdt maxepisdur; run; %put NOTE: ********END OF MACRO: ms_createt5episodes v1.0********; %mend ms_createt5episodes;