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!!

2 REPLIES 2
PhilC
Rhodochrosite | Level 12

I found this gem of a math formula dealing with overlaping units.  Link is here:

http://baodad.blogspot.com/2014/06/date-range-overlap.html 

 

Maybe this will help you flag for overlapped time periods.  This code below will not handle overlaps of three or more time-periods, mind you.  In the code, I commented out the "negative" prescription to show how this formula can work.

 

data have(label='Prescription Data');
   length id $10;
   infile datalines  truncover;
   input Drug:$1 Prescription_Date:MMDDYY8. Days_Supplied:4.0;
   Prescription_Date_end=Prescription_Date+Days_Supplied-1;
     format Prescription_Date: mmddyy10.;
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
;;;;
proc sort;
 by id;
run;


data next;
  do until (last.ID);
    set have;
      by ID;
    Prescription_Date_lag    =lag(Prescription_Date);  
    Prescription_Date_end_lag=lag(Prescription_Date_end); 
      format Prescription_Date: mmddyy10.;

    if  first.ID 
      then period_overlap=.;
      else do;
        period_overlap=Min (Prescription_Date_end_lag - Prescription_Date_lag ,
                            Prescription_Date_end_lag - Prescription_Date,
                            Prescription_Date_end     -  Prescription_Date,
                            Prescription_Date_end     -  Prescription_Date_lag
                            );/*http://baodad.blogspot.com/2014/06/date-range-overlap.html*/
        if period_overlap<1
          then period_overlap=0;
    end; 
    output;
  end;
run;

 

Drug Prescription_Date Days_Supplied period_overlap
A 11/8/2016 7 .
A 11/15/2016 21 0
A 12/6/2016 28 0
B 3/8/2017 30 0
A 4/3/2017 3 2
A 5/15/2017 3 0
A 6/5/2017 3 0
B 6/14/2017 30 0
A 10/5/2017 15 0
A 10/25/2017 15 0
Tom
Super User Tom
Super User

Try reading some of the papers published on PDC calculation.

 

@sas.com PDC calculations

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1270 views
  • 0 likes
  • 3 in conversation