<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to account for varying doses within a data set? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-account-for-varying-doses-within-a-data-set/m-p/906086#M357813</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I have the following dataset and trying to do a similar thing to this paper:&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/043-2007.pdf" target="_blank" rel="nofollow noopener noreferrer"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/043-2007.pdf&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90755iD07CAF28B49CBAE4/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;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):&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;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)&amp;lt;= start_dt + ii -1 &amp;lt;= filldates(i)+days_supply(i)-1
        then daydummy(ii)=1;
    end;
    do u=2 to 5 while (filldates(u) ne .);
        if filldates(u)&amp;lt;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;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;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.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Dec 2023 19:24:02 GMT</pubDate>
    <dc:creator>g_nohmie</dc:creator>
    <dc:date>2023-12-04T19:24:02Z</dc:date>
    <item>
      <title>How to account for varying doses within a data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-account-for-varying-doses-within-a-data-set/m-p/906086#M357813</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have the following dataset and trying to do a similar thing to this paper:&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/043-2007.pdf" target="_blank" rel="nofollow noopener noreferrer"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/043-2007.pdf&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90755iD07CAF28B49CBAE4/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;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):&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;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)&amp;lt;= start_dt + ii -1 &amp;lt;= filldates(i)+days_supply(i)-1
        then daydummy(ii)=1;
    end;
    do u=2 to 5 while (filldates(u) ne .);
        if filldates(u)&amp;lt;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;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;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.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 19:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-account-for-varying-doses-within-a-data-set/m-p/906086#M357813</guid>
      <dc:creator>g_nohmie</dc:creator>
      <dc:date>2023-12-04T19:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to account for varying doses within a data set?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-account-for-varying-doses-within-a-data-set/m-p/906379#M357894</link>
      <description>&lt;P&gt;I find it a little hard tracking your code.&amp;nbsp; So I took a different approach.&amp;nbsp; This code proceeds from prescription to prescription (adjusted to prevent overlap and exceeding 98 days) and creates a _DOSE_HISTORY array, indexed by date.&amp;nbsp; Instead of inserting dummy values into the array, it inserts does levels.&amp;nbsp; Use the COUNT function for days_covered, and the SUM function to get average dose over 98 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My real confusion is what is the role of START_DT, which this code ignores?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code is untested in the absence of sample data in the form of a working DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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&amp;lt;=_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;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Dec 2023 04:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-account-for-varying-doses-within-a-data-set/m-p/906379#M357894</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-12-06T04:17:07Z</dc:date>
    </item>
  </channel>
</rss>

