**************************************************************************************************** * PROGRAM OVERVIEW **************************************************************************************************** * * PROGRAM: ms_findgap.sas * * Created (mm/dd/yyyy): 07/31/2014 * Last modified: 01/19/2018 * Version: 1.1 * *-------------------------------------------------------------------------------------------------- * PURPOSE: * This program will find any first date that is the first after a user * defined gap (or the very first). * * Program inputs: * -Dataset in which gaps are to be looked for * * Program outputs: * -Dataset with the gap condition applied * * PARAMETERS: * -InFile = Name of the dataset in which gaps are to be found * -OutFile= Name of the output dataset with the gap condition applied * -sort = List of variables used to sort InFile * -NoDup = Duplicate records removal indicator used when sorting * -gapby = Group of variable that indicates how to look for gaps * -gap = Gap value to look for between records according to gapby * -dupby = Group of variable that indicates how to remove duplicates * * 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 01/19/18 AP Added deduplication of Adate based on max(expiredt) * ***************************************************************************************************; %macro ms_findgap(InFile=, OutFile=, sort=, NoDup= ,gapby=, gap=, dupby=); %put =====> MACRO CALLED: ms_findgap v1.1; data _null_; call symputx("lastwrd",scan("&gapby.",countw("&gapby."))); call symputx("lastwrddup",scan("&dupby.",countw("&dupby."))); if "&NoDup."="Y" then call symputx("nodupkey","nodupkey"); else call symputx("nodupkey",""); run; %put &lastwrd. &nodupkey.; proc sort data=&InFile. &nodupkey. out=&OutFile.; by &sort.; run; %if "&NoDup."="Y" %then %do; *remove duplicate adate, and keep longer duration (to ensure washout applied to longer duration); data &OutFile.; set &OutFile.; by &dupby.; if first.&lastwrddup.; run; %end; *Compute gaps; data &OutFile.; set &OutFile.; by &gapby.; DaysUntreated=Adate-lag(ExpireDt); gap=DaysUntreated > max(&gap.,0); if &gap.=. then gap=0; *If washper=., then only first date is valid (formerly MIN in the MIN,SING, MULT sequence); if first.&lastwrd. then gap=1; *first one always counts as being a potential index date; if gap or (&gap.=0); * if washper =0 then all claims are deemed potential indedate wrt own self; drop gap; run; %put NOTE: ********END OF MACRO: ms_findgap v1.1********; %mend ms_findgap;