BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Banke
Pyrite | Level 9

Hello everyone, I need your help please:

I want to calculate the average daily dose (ADD) for each patient (= quantity_supplied/days_supplied) for the first 6 months of prescription fills (fill_date), such that for each patient, I have a single value of ADD that corresponds to the average number of tablets they took per day from the first time they received the medication (index date) till up to 6 months.

Your help will be greatly appreciated. Thank you

patient_id fill_date index_date quantity_supplied days_supplied
1 01/11/2018 01/11/2018 140 30
1 01/12/2018 01/11/2018 140 30
1 01/22/2018 01/11/2018 160 30
1 02/16/2018 01/11/2018 90 90
1 03/19/2018 01/11/2018 90 90
1 06/18/2018 01/11/2018 90 90
2 02/12/2017 02/12/2017 120 30
2 03/23/2017  02/12/2017 120 30
2 06/14/2017  02/12/2017 90 90
2 07/30/2017  02/12/2017 90 90
2 08/31/2017  02/12/2017 60 60
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

So just to make sure I understand completely, for patient 1 we would sum all of the quantity_supplied and then divide by the sum of days_supplied, because the last record 6/18/2018 is less than 6 months after the index date. For patient 2 we would do the same thing with all records except the record for 8/31/2017 because this is more than 6 months after the index date.

 

Is this correct?

 

If so, try this (UNTESTED CODE):

 

proc summary data=have(where=(fill_date<intnx('month',index_date,6,'s'))) nway;
    class patient_id;
    var quantity_supplied days_supplied;
    output out=sums sum=;
run;
data want; 
    set sums;
    add = quantity_supplied/days_supplied;
run;

 

 

This assumes that your date values are valid numeric SAS date values (representing the integer number of days since 01JAN1960). Otherwise, the code will not work.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

So just to make sure I understand completely, for patient 1 we would sum all of the quantity_supplied and then divide by the sum of days_supplied, because the last record 6/18/2018 is less than 6 months after the index date. For patient 2 we would do the same thing with all records except the record for 8/31/2017 because this is more than 6 months after the index date.

 

Is this correct?

 

If so, try this (UNTESTED CODE):

 

proc summary data=have(where=(fill_date<intnx('month',index_date,6,'s'))) nway;
    class patient_id;
    var quantity_supplied days_supplied;
    output out=sums sum=;
run;
data want; 
    set sums;
    add = quantity_supplied/days_supplied;
run;

 

 

This assumes that your date values are valid numeric SAS date values (representing the integer number of days since 01JAN1960). Otherwise, the code will not work.

--
Paige Miller
Banke
Pyrite | Level 9
Yes, you are correct. It worked perfectly. Thank you so much!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 828 views
  • 2 likes
  • 2 in conversation