BookmarkSubscribeRSS Feed
alaxman
Obsidian | Level 7

Hello,

 

I'm trying to compute # of days (p_dayscovered) a patient is taking medication over the course of 365 days starting 11/18/2016. The Prescription Date is the day when the patient is prescribed or refills their medication and the # of days of prescription supplied is how many days they got the medication for.

 

For example, in the table below, on 11/8, the patient gets the prescription for 7 days. It is assumed they start taking the medication on the prescription date. So the medication would run out on 11/8 + 7 days = 11/14. The patient gets the next medication on 11/15 for 21 days which means there is no gap in the medication between first prescription and the refill.

 

However, after the refill on 12/6 for 28 days, the patient goes off the medication for a while before starting on another drug on 3/8/17. So, we would stop counting for p_dayscovered after 12/6 + 28 days, but restart starting 3/8/17.

 

data WORK.CLASS(label='Prescription Data');
   infile datalines dsd truncover;
   input Drug:$1 Prescription_Date:MMDDYY8. Days_Supplied:32.;
 Datalines;
A 11/8/16  7
A 11/15/16 21
A 12/6/16  28
B 3/8/17   30
B 4/7/17   -4
A 4/3/17   3
A 5/15/17  3
A 6/5/17   3
B 6/14/17  30
A 10/5/17  15
A 10/25/17 15
;;;;

The table looks like this:

Drug Prescription Date # of days of prescription supplied

A

11/8/16 7
A 11/15/16 21
A 12/6/16 28
B 3/8/17 30
B 4/7/17 -4
A 4/3/17 3
A 5/15/17 3
A 6/5/17 3
B 6/14/17 30
A 10/5/17 15
A 10/25/17 15

 

Here is my code to compute the p_dayscovered:

 

 

 

*"daydummy" array creates a dummy variable for each day in the review period;
*"filldates" & "days_supply" arrays groups the Prescription Date & # of Days supplied variables, setting up the DO loops;

data  pdc_3M_12M;
set  both_3M_12M; 
array daydummy(365) day1-day365;
array filldates(*) svcdate1-svcdate%eval(&max_3M.);
array days_supply(*) daysupp1-daysupp%eval(&max_3M.);

	do ii=1 to 365; daydummy(ii)=0;end;
	do ii=1 to 365;
        do i = 1 to dim(filldates) while (filldates(i) ne .);

*Flags the days of the review period that the patient was supplied the medication;
	if filldates(i)<= start_dt + ii -1 <= filldates(i)+days_supply(i)-1
	then daydummy(ii)=1;
	end;
	end;
drop i ii; 

*dayscovered sums the daydummy variables. This sum is used as the numerator in calculating p_dayscovered, the proportion of days medication was supplied in the 365 day study period;

dayscovered= sum(of day1 - day365);label dayscovered= "Total Days Covered";
p_dayscovered=dayscovered/365; label p_dayscovered= "Proportion of Days Covered";
run;

 

 

The code works in all cases except the overlap edge case which I have highlighted in red, which is:

  1. On 3/8/17, the patient gets a 30 day prescription for Drug B
  2. However, on 4/3/17, the patient gets a 3 day prescription for Drug A

In this case, the counting for Drug B should stop on 4/2/17 and the counting for Drug A should begin starting on 4/3/17. 

My code adds a '1' flag for all days starting 3/8/17 + 30 days = 4/6/17 whereas, I want the code to stop adding the '1' flag on 4/2/17 and then add the '1' flags starting 4/3/17 + 3 ending on 4/5/17. 

 

The total p_dayscovered = 150 because of what I mentioned above, but my code because of not accounting for the overlap counts it as 151

 

Can someone help me figure out how to write this overlap exception condition?

 

Thanks so much!!

 

 

5 REPLIES 5
andreas_lds
Jade | Level 19

Please post data in usable form, those tables are nice to look at, but completely useless as data source.

It seems, by the way, strange, that there is no variable identifying the patient in your data.

alaxman
Obsidian | Level 7
Hello! I'm new to SAS and do not know how to provide the table as a data source. The code I listed in the post is just one snippet of the larger project because this is the portion that I need help with
ballardw
Super User

Where does the macro variable &max_3m get its value? What value does it have in your example?

 

What the heck is negative number of days? Does someone mug the patient and take pills away?

 

Are you dates actual SAS date values or character values?

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

 

Remove any sensitive information but I suspect that a patient identifier is going to be needed.

 

This may be easier to deal with odd cases by making a long data set. Start by sorting by Patient identifier, drug and prescription date (which pretty much requires an actual SAS date value).

alaxman
Obsidian | Level 7
Thanks. I edited the post to provide the table as a data source as you suggested.

Where does the macro variable &max_3m get its value? What value does it have in your example?
Response: This is a previously defined variable in the larger code to account for all patients and all the prescriptions they receive based on the sample dataset I am working with. In the example dataset i've provided the value for &max_3m =11

What the heck is negative number of days? Does someone mug the patient and take pills away?
Response: I've to adjust the Prescription date in case there is an overlap where the patient goes to get a refill before the current prescription runs out OR switches the Drug before prescription runs out. In this dataset, the patient receives a 30 day fill for Drug A on 3/8/17, but then switches to Drug B on 4/3/17. So our assumption is that the patient stops taking Drug A on 4/2/17 and starts with Drug B on 4/3/17


Are you dates actual SAS date values or character values?
They are SAS date values
ChrisNZ
Tourmaline | Level 20

You might have to show how each # of days figure is calculated for each line so we understand better.

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
  • 5 replies
  • 1065 views
  • 0 likes
  • 4 in conversation