BookmarkSubscribeRSS Feed
cf8585
Calcite | Level 5

Hello,

I have a large dataset that has a table set up like below.  I am trying to determine the average # of days each NDC is filled late i.e., for memberid drug x should be refilled on 2/1/2020 however it was filled on 2/15/10 so it was 14 days late, etc.  I need the average late time per each NDC.  Can someone please help me out with coding this?

Thanks

 

 

MemberIDDateNDCQuantityDispensedDaySupply
11/1/2020X3030
11/10/2020Y1515
12/15/2020X3030
13/19/2020X3030
14/10/2020Y1515
21/15/2020X180180
23/18/2020Y3030
24/15/2020X3030
26/18/2020Y180

180

1 REPLY 1
HB
Barite | Level 11 HB
Barite | Level 11

 

I am not a good programmer.  This is very inelegant and not the best way.

 

I will assume the expected refill date is issue date plus days of supply. 

 

Given:

data scriptinfo;
   input MemberID issuedate:mmddyy10. NDC:$1. QuantityDispensed DaySupply;
datalines;
1 1/1/2020 X 30 30
1 1/10/2020 Y 15 15
1 2/15/2020 X 30 30
1 3/19/2020 X 30 30
1 4/10/2020 Y 15 15
2 1/15/2020 X 180 180
2 3/18/2020 Y 30 30
2 4/15/2020 X 30 30
2 6/18/2020 Y 180 180
;
run;

 

We can sort the data by patient, drug, and date. Then calculate an expire date and a dayslate.

 

proc sort data =  scriptinfo;
	by memberid ndc issuedate;
run;


data manipulate;
	set scriptinfo;
	by memberid ndc issuedate;
	expiredate = issuedate + daysupply;
	counter = first.ndc; *visual marker;
	dayslate = issuedate -lag(expiredate);
	if counter = 1 then dayslate = .;
	format issuedate date9. expiredate date9.;
run;

this gives us:

 

MemberID issuedate NDC QuantityDispensed DaySupply expiredate counter dayslate
1 1-Jan-20 X 30 30 31-Jan-20 1 .
1 15-Feb-20 X 30 30 16-Mar-20 0 15
1 19-Mar-20 X 30 30 18-Apr-20 0 3
1 10-Jan-20 Y 15 15 25-Jan-20 1 .
1 10-Apr-20 Y 15 15 25-Apr-20 0 76
2 15-Jan-20 X 180 180 13-Jul-20 1 .
2 15-Apr-20 X 30 30 15-May-20 0 -89
2 18-Mar-20 Y 30 30 17-Apr-20 1 .
2 18-Jun-20 Y 180 180 15-Dec-20 0 62

 

indicating patient 1 was 15 and then 3 days late when refilling his X while patient 2 was 89 days early refilling her 180 day supply of x. 

 

You could probably average dayslate column by patient or by drug.  

 

Maybe this will get you closer to where you need to be.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 243 views
  • 0 likes
  • 2 in conversation