if you want "two days apart", change
dif(date) ne 1
into
dif(date) > 2
Hi,
the rules you follow are not clear to me:
"If on Jan 15th, the same member gets another prescription for a 10 days, the value would still be 30 days. But if another member gets one prescription on Jan 1st for 30 days and another prescription on Jan 25th for 10 days the days streak would now be at 35 days"
With the rows 30 and 10 you create one time a row of 30 and the other time a row of 35, what's the trigger? is it a date other than the 15th of the month? and what is the rule, is it 30+10/2?
"If there was a gap of more than 2 days between prescriptions a new set of days would be created based on above algorithm."
Please clarify and provide an example
- Cheers -
Assuming I understood what you mean.
data have;
input MemberId Fill_date : mmddyy12. Days_supply_cnt;
format fill_date mmddyy10.;
cards;
12345 01/01/2017 30
12345 01/15/2017 10
12345 02/10/2017 60
23456 01/01/2017 30
23456 01/25/2017 10
23456 04/01/2017 90
;
run;
data temp;
set have;
do date=fill_date to fill_date+Days_supply_cnt-1;
output;
end;
keep memberid date;
format date mmddyy10.;
run;
proc sort data=temp out=temp1 nodupkey;
by memberid date;
run;
data temp2;
set temp1;
by memberid;
if first.memberid or dif(date) ne 1 then group+1;
run;
proc freq data=temp2 noprint;
table memberid*group/out=want list;
run;
if you want "two days apart", change
dif(date) ne 1
into
dif(date) > 2
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.