<?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 Re: Need help with my code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/762753#M241527</link>
    <description>&lt;P&gt;Where does the macro variable &amp;amp;max_3m get its value? What value does it have in your example?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What the heck is negative number of days? Does someone mug the patient and take pills away?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you dates actual SAS date values or character values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; 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 &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remove any sensitive information but I suspect that a patient identifier is going to be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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).&lt;/P&gt;</description>
    <pubDate>Fri, 20 Aug 2021 05:19:10 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-08-20T05:19:10Z</dc:date>
    <item>
      <title>Need help with my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/762748#M241522</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to compute &lt;STRONG&gt;# of days (p_dayscovered)&lt;/STRONG&gt; a patient is taking medication over the course of &lt;STRONG&gt;365 days&amp;nbsp;&lt;/STRONG&gt;starting &lt;STRONG&gt;11/18/2016.&amp;nbsp;&lt;/STRONG&gt;The &lt;STRONG&gt;Prescription Date&lt;/STRONG&gt; is the day when the patient is prescribed or refills their medication and the&amp;nbsp;&lt;STRONG&gt;# of days of prescription supplied&amp;nbsp;&lt;/STRONG&gt;is how many days they got the medication for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;&lt;STRONG&gt;p_dayscovered&amp;nbsp;&lt;/STRONG&gt;after 12/6 + 28 days, but restart starting 3/8/17.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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
;;;;
&lt;/PRE&gt;
&lt;P&gt;The table looks like this:&lt;/P&gt;
&lt;TABLE border="1" width="50%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%" class="lia-align-center"&gt;&lt;STRONG&gt;Drug&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="12.5%" class="lia-align-center"&gt;&lt;STRONG&gt;Prescription Date&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="12.5%" class="lia-align-center"&gt;&lt;STRONG&gt;# of days of prescription supplied&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="12.5%"&gt;11/8/16&lt;/TD&gt;
&lt;TD width="12.5%"&gt;7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;A&lt;/TD&gt;
&lt;TD width="12.5%"&gt;11/15/16&lt;/TD&gt;
&lt;TD width="12.5%"&gt;21&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;A&lt;/TD&gt;
&lt;TD width="12.5%"&gt;12/6/16&lt;/TD&gt;
&lt;TD width="12.5%"&gt;28&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;&lt;FONT color="#FF6600"&gt;B&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="12.5%"&gt;&lt;FONT color="#FF6600"&gt;3/8/17&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="12.5%"&gt;&lt;FONT color="#FF6600"&gt;30&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;&lt;FONT color="#FF6600"&gt;B&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="12.5%"&gt;&lt;FONT color="#FF6600"&gt;4/7/17&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="12.5%"&gt;&lt;FONT color="#FF6600"&gt;-4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;&lt;FONT color="#FF6600"&gt;A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="12.5%"&gt;&lt;FONT color="#FF6600"&gt;4/3/17&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="12.5%"&gt;&lt;FONT color="#FF6600"&gt;3&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;A&lt;/TD&gt;
&lt;TD width="12.5%"&gt;5/15/17&lt;/TD&gt;
&lt;TD width="12.5%"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;A&lt;/TD&gt;
&lt;TD width="12.5%"&gt;6/5/17&lt;/TD&gt;
&lt;TD width="12.5%"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;B&lt;/TD&gt;
&lt;TD width="12.5%"&gt;6/14/17&lt;/TD&gt;
&lt;TD width="12.5%"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;A&lt;/TD&gt;
&lt;TD width="12.5%"&gt;10/5/17&lt;/TD&gt;
&lt;TD width="12.5%"&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;A&lt;/TD&gt;
&lt;TD width="12.5%"&gt;10/25/17&lt;/TD&gt;
&lt;TD width="12.5%"&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my code to compute the&amp;nbsp;&lt;STRONG&gt;p_dayscovered:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;*"daydummy" array creates a dummy variable for each day in the review period;
*"filldates" &amp;amp; "days_supply" arrays groups the Prescription Date &amp;amp; # 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(&amp;amp;max_3M.);
array days_supply(*) daysupp1-daysupp%eval(&amp;amp;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)&amp;lt;= start_dt + ii -1 &amp;lt;= 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;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code works in all cases except the overlap edge case which I have highlighted in &lt;FONT color="#FF6600"&gt;red&lt;FONT color="#000000"&gt;, which is:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;On 3/8/17, the patient gets a 30 day prescription for Drug B&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;However, on 4/3/17, the patient gets a 3 day prescription for Drug A&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;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.&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;My code adds a &lt;STRONG&gt;'1'&lt;/STRONG&gt; flag for all days starting &lt;STRONG&gt;3/8/17 + 30 days = 4/6/17&lt;/STRONG&gt; whereas, I want the code to stop adding the &lt;STRONG&gt;'1'&lt;/STRONG&gt; flag on &lt;STRONG&gt;4/2/17&lt;/STRONG&gt; and then add the '1' flags starting &lt;STRONG&gt;4/3/17 + 3&lt;/STRONG&gt; ending on &lt;STRONG&gt;4/5/17.&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;The total&amp;nbsp;p_dayscovered = 150 because of what I mentioned above, but my code because of not accounting for the overlap counts it as 151&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;Can someone help me figure out how to write this overlap exception condition?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;Thanks so much!!&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 03:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/762748#M241522</guid>
      <dc:creator>alaxman</dc:creator>
      <dc:date>2021-08-25T03:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/762751#M241525</link>
      <description>&lt;P&gt;Please post data in usable form, those tables are nice to look at, but completely useless as data source.&lt;/P&gt;
&lt;P&gt;It seems, by the way, strange, that there is no variable identifying the patient in your data.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 05:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/762751#M241525</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-20T05:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/762753#M241527</link>
      <description>&lt;P&gt;Where does the macro variable &amp;amp;max_3m get its value? What value does it have in your example?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What the heck is negative number of days? Does someone mug the patient and take pills away?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you dates actual SAS date values or character values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; 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 &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remove any sensitive information but I suspect that a patient identifier is going to be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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).&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 05:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/762753#M241527</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-20T05:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/763774#M241887</link>
      <description>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</description>
      <pubDate>Wed, 25 Aug 2021 03:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/763774#M241887</guid>
      <dc:creator>alaxman</dc:creator>
      <dc:date>2021-08-25T03:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/763776#M241888</link>
      <description>Thanks. I edited the post to provide the table as a data source as you suggested.&lt;BR /&gt;&lt;BR /&gt;Where does the macro variable &amp;amp;max_3m get its value? What value does it have in your example?&lt;BR /&gt;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 &amp;amp;max_3m =11&lt;BR /&gt;&lt;BR /&gt;What the heck is negative number of days? Does someone mug the patient and take pills away?&lt;BR /&gt;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&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Are you dates actual SAS date values or character values?&lt;BR /&gt;They are SAS date values</description>
      <pubDate>Wed, 25 Aug 2021 03:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/763776#M241888</guid>
      <dc:creator>alaxman</dc:creator>
      <dc:date>2021-08-25T03:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/764098#M241991</link>
      <description>&lt;P&gt;You might have to show how each # of days figure is calculated for each line so we understand better.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 03:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-my-code/m-p/764098#M241991</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-26T03:24:26Z</dc:date>
    </item>
  </channel>
</rss>

