I have the following dataset and trying to do a similar thing to this paper: https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/043-2007.pdf
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; end; 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); end; end; drop i ii; dayscovered=sum(of day1 - day98);label dayscovered='Total Days Covered'; p_dayscovered=dayscovered/98;label p_dayscovered='Proportion of Days Covered'; run;
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;
_beg_window=fd{1};
_end_window=_beg_window+97;
_end_f=_beg_window-1;
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);
_dose_history{_date}=dos{_f};
end;
end;
days_covered=count(of _dose_history{*});
p_dayscovered=days_covered/98;
average_dose=sum(of _dose_history{*})/98;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.