BookmarkSubscribeRSS Feed
Calcite | Level 5

I have the following dataset and trying to do a similar thing to this paper:


These patients got multiple prescriptions during a period of time. I am looking at a 98 days window. I initially wanted to see which days within the 98-day period the patient uses a medication and wanted to take care of overlapping periods by shifting them to the day after the end of prescription 1 (filled_dt)in case prescription 1 and prescription 2 overlap. I created 98 indicator variables with values of 1 in case the filled_dt and days supply cover the 98-day period (and which ones exactly). This is my code (feel free to correct me, but I have not found a mistake juste yet):

data pdc;
set shoe;
array daydummy(98) day1-day98;
array filldates(*) fill_dt1 - fill_dt5;
array days_supply(*) days_supply1-days_supply5;
do ii=1 to 98; daydummy(ii)=0;end;
do ii=1 to 98;
    do i = 1 to dim(filldates) while (filldates(i) ne .);
        if filldates(i)<= start_dt + ii -1 <= filldates(i)+days_supply(i)-1
        then daydummy(ii)=1;
    do u=2 to 5 while (filldates(u) ne .);
        if filldates(u)<filldates(u-1)+days_supply(u-1)
        then filldates(u)=filldates(u-1)+days_supply(u-1);
drop i ii;
dayscovered=sum(of day1 - day98);label dayscovered='Total Days Covered';
p_dayscovered=dayscovered/98;label p_dayscovered='Proportion of Days Covered';

The second "do" takes care of crediting the overlaps. However, I have an added complexity: Each week is associated with an average daily dose (fill_dt1 and dose_1 and days_supply1 go hand-in-hand together). Basically, the prescription was filled on this date (filled_dt1) for this long(days_supply1 ) with an average daily dose (dose_1). How do I multiply my indicator weeks (day1-day98) with the average daily dose associated with each filled prescription. I also need to keep taking into account the shift once two prescriptions overlap, as well as days covered and percentage of days covered. I would preferably have an extra 98 columns added to my data set, but instead of having 1 where they should be, I would have the average daily dose. 


I find it a little hard tracking your code.  So I took a different approach.  This code proceeds from prescription to prescription (adjusted to prevent overlap and exceeding 98 days) and creates a _DOSE_HISTORY array, indexed by date.  Instead of inserting dummy values into the array, it inserts does levels.  Use the COUNT function for days_covered, and the SUM function to get average dose over 98 days.


My real confusion is what is the role of START_DT, which this code ignores?


This code is untested in the absence of sample data in the form of a working DATA step.


data want (drop=_:);
  set have;
  array _dose_history {%sysevalf("01jan1998"d):%sysevalf("31dec2010"d)}; /*Date range of entire study*/

  array fd  {*} fill_dt1-fill_dt5; ;  
  array ndays {*} days_supply1-day_supply5;
  array dos {*} dose_1-dose_5;



  do _f=1 to count(of fd{*});
    _beg_f=max(fd{_f},_end_f+1);        /*Push this fill date range forward (_end_f +1) if overlap*/
    _end_f=_beg_f + ndays(_f)-1;
    do _date=_beg_f to _end_f while (_date<=_end_window);

  days_covered=count(of _dose_history{*});
  average_dose=sum(of _dose_history{*})/98;
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets



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
  • 1 reply
  • 2 in conversation