Unfortunately this logic didn't work. I've included new example data and you can see that it's flagging too many rows with Recycle_Ind=1 . It has to do with this line of code: if OldThru < (FROM_DT-1) and (FROM_DT - OldThru) < 180 then Recycle_ID = 1;
This assumes that there will only be one day's difference between the current FROM_DT and the previous THRU_DT, when in fact there could be a larger gap. I extended the gap by more than 1 day for the records that are marked as incorrect below.
If you have any thoughts on how to correct this I'd love to get this working.
For the input data below the following records are identified:
ID PI FROM_DT THRU_DT
123456 1234567890 14SEP2017 12NOV2017 123456 1234567890 15NOV2017 11JAN2018 INCORRECTLY RECYCLE=1 123456 2345678901 27FEB2018 27APR2018 123456 2345678901 28APR2018 26JUN2018 123456 2345678901 27JUN2018 25AUG2018 234567 3234567890 14SEP2017 12FEB2018 234567 4345678901 20FEB2018 25FEB2018 234567 3234567890 12MAR2018 08MAY2018 RECYCLE=1 234567 3234567890 11MAY2018 12MAY2018 INCORRECTLY RECYCLE=1 234567 4345678901 13MAY2018 09JUL2018 RECYCLE=1 234567 3234567890 10JUL2018 07SEP2018 RECYCLE=1
data have; informat FROM_DT date9. THRU_DT date9.; format FROM_DT date9. THRU_DT date9.; input ID PI FROM_DT THRU_DT; datalines; 123456 1234567890 14SEP2017 12NOV2017 123456 1234567890 15NOV2017 11JAN2018 123456 2345678901 27FEB2018 27APR2018 123456 2345678901 28APR2018 26JUN2018 123456 2345678901 27JUN2018 25AUG2018 234567 3234567890 14SEP2017 12FEB2018 234567 4345678901 20FEB2018 25FEB2018 234567 3234567890 12MAR2018 08MAY2018 234567 3234567890 11MAY2018 12MAY2018 234567 4345678901 13MAY2018 09JUL2018 234567 3234567890 10JUL2018 07SEP2018 ; run;
* sort to group ID's on PI values; proc sort data=have out=want; by ID PI FROM_DT; run;
* pick ID with recurrent PI, not concecutive, but within 180 days; data w3 (drop=OldPI OldThru); set wANT; by ID PI; OldPI = lag(PI); OldThru = lag(THRU_DT); if not first.PI then do; if OldThru < (FROM_DT-1) and (FROM_DT - OldThru) < 180 then Recycle_ID = 1; end; run;
... View more