BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mzahid
Fluorite | Level 6
Hi,
I need help on creating a consecutive days value based on memberid, fill_date and days_supply_cnt variables for a pharmacy claims SAS 
 
dataset.  I'm trying to find out the consecutive streak of a drug use for each member for the last six months.  For example a 30 days drug 
 
supply on Jan 1st would give a member with memberid 12345 a value of 30 days.  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.  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 Note: This data is already limited to specific drug for our analysis,
 
See example below
 
MemberId .    Fill_date            Days_supply_cnt
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
 
 
Desired OutPut
MemberId .  Consec_days
12345         30
12345         60
23456         35
23456         90
 
 
I would appreciate any help on this.
 
Thanks
 
Zahid Khan
 
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

if you  want  "two days apart", change

 

dif(date) ne 1

into 

dif(date) > 2

 

View solution in original post

4 REPLIES 4
Oligolas
Barite | Level 11

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 -

Ksharp
Super User

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;
mzahid
Fluorite | Level 6
Thank you so much for your help.  I tested the code, it works for the most part.  There are some situations where group =1 would end two days before the group 2 starts.  In the below example Group 1 has a count of 3 and group 2 has a count of 5.  If I wanted to combine group 1 and group 2 so the total count would be 8, since they are only two days apart.  How would I go about it.  Again, thanks for your time. 
MemberId .     fill_date             Group123456 .            21oct2017 .       1123456.             22oct2017 .       1123456 .            23oct2017 .       1123456 .            25oct2017 .       2123456 .            26oct2017 .       2123456 .            27oct2017 .       2123456 .            28oct2017 .       2123456 .            29oct2017 .       2

Ksharp
Super User

if you  want  "two days apart", change

 

dif(date) ne 1

into 

dif(date) > 2

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1285 views
  • 0 likes
  • 3 in conversation