@Allegra wrote:
I meant consecutive days. Taking Patient 3 as an example:
1st prescription: 31AUG2013: NO FLAG
2nd prescription to 5th prescription: (NDC: 591261205) 09DEC2013 TO 12DEC2013 ie no break-in days which equates to 4 days.
6th prescription to 8th: (NDC: 591261205) 19JUNE2014 TO 21STJUNE2014 ie no break in days which equates to 3 days
Question: why is duration not 7days because of same NDC?
Explanation: 5th prescription was taken 12DEC2013 while 6th prescription was on 19JUNE2014 (a gap of almost 6 months), thus I want to keep them separate.
If patient 3, however, had 6th to 8th prescription from 13DEC2013 TO 15DEC2013 for that same NDC, Duration would have been added to 7days.
Sorry, English is not my first language, so I am trying to explain as best as I can.
Again, thank you for your time:)
proc sort data=have;
by id ndc date;
run;
data want;
set have;
by id ndc;
prev_date=lag(date);
if first.ndc or date-prev_date>1 then duration=0;
duration+flag;
if duration=0 or last.ndc or date-prev_date>1 then output;
drop prev_date;
run;
... View more