<?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 Calculate days of supply by fill date while correcting for refills in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468194#M285414</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with pharmacy claim data, and would like to calculate how many consecutive days a person was&amp;nbsp;on&amp;nbsp;a prescription. The data I have is constructed by claim, so each claim corresponds to one prescription, if a patient get one drug on 10/21/2015 for 20 days of supply, then he got an refill on 11/10/2015 for 20 days, since there was no gap between the refill and the end date of last prescription, their days of supply would be summed up. Thus I would like to know how many consecutive days this person was on a&amp;nbsp;&lt;SPAN&gt;prescription.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data structure is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data temp;&lt;BR /&gt;input patid fill_dt : mmddyy10. days_sup;&lt;BR /&gt;format fill_dt mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 10/21/2015 20&lt;BR /&gt;1 11/10/2015 20&lt;BR /&gt;1 11/30/2015 30&lt;BR /&gt;2 5/1/2013 20&lt;BR /&gt;2 5/20/2013 10&lt;BR /&gt;2 6/10/2013 3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if a claim's end date which is&amp;nbsp;defined as&amp;nbsp;the fill_dt + days_sup is less than or equal to the next claim's fill_dt, I would like to sum their's days_sup together.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore the desired output would be like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 10/21/2015 70&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 5/1/2013 30&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 6/10/2013 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have struggle with for a few days. Any help would be appreciated! Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jun 2018 19:49:00 GMT</pubDate>
    <dc:creator>ncy</dc:creator>
    <dc:date>2018-06-08T19:49:00Z</dc:date>
    <item>
      <title>Calculate days of supply by fill date while correcting for refills</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468194#M285414</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with pharmacy claim data, and would like to calculate how many consecutive days a person was&amp;nbsp;on&amp;nbsp;a prescription. The data I have is constructed by claim, so each claim corresponds to one prescription, if a patient get one drug on 10/21/2015 for 20 days of supply, then he got an refill on 11/10/2015 for 20 days, since there was no gap between the refill and the end date of last prescription, their days of supply would be summed up. Thus I would like to know how many consecutive days this person was on a&amp;nbsp;&lt;SPAN&gt;prescription.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data structure is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data temp;&lt;BR /&gt;input patid fill_dt : mmddyy10. days_sup;&lt;BR /&gt;format fill_dt mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 10/21/2015 20&lt;BR /&gt;1 11/10/2015 20&lt;BR /&gt;1 11/30/2015 30&lt;BR /&gt;2 5/1/2013 20&lt;BR /&gt;2 5/20/2013 10&lt;BR /&gt;2 6/10/2013 3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if a claim's end date which is&amp;nbsp;defined as&amp;nbsp;the fill_dt + days_sup is less than or equal to the next claim's fill_dt, I would like to sum their's days_sup together.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore the desired output would be like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 10/21/2015 70&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 5/1/2013 30&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 6/10/2013 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have struggle with for a few days. Any help would be appreciated! Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 19:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468194#M285414</guid>
      <dc:creator>ncy</dc:creator>
      <dc:date>2018-06-08T19:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days of supply by fill date while correcting for refills</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468201#M285415</link>
      <description>&lt;P&gt;This works for your example data:&lt;/P&gt;
&lt;PRE&gt;proc sort data=temp;
   by patid fill_dt;
run;
 
data want;
   set temp;
   by patid fill_dt;
   retain series_date day_tot;
   format series_date mmddyy10.;
   if first.patid then do;
      series_date=fill_dt;
      day_tot=days_sup;
   end;
   else if fill_dt le (series_date+day_tot) then do;
      day_tot=day_tot+days_sup;
   end;
   else if fill_dt gt (series_date+day_tot) then do;
      output;
      series_date=fill_dt;
      day_tot=days_sup;

   end;

   if last.patid then do;
      output;
      call missing(series_date, day_tot);
   end;
   keep patid series_date day_tot;
   label 
      series_date = 'First Fill date for sequence'
      day_tot     = 'Total days supply for series'
   ;
run; &lt;/PRE&gt;
&lt;P&gt;BY processing allows you identify the first and last record for a patid value to set/reset accumulating variables. Retain says to keep the variable values across iterations of the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Specific OUTPUT statements control when the data is actually written to the data set.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2018 21:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468201#M285415</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-06T21:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days of supply by fill date while correcting for refills</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468340#M285416</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input patid fill_dt : mmddyy10. days_sup;
end_date=fill_dt+days_sup;
format fill_dt end_date mmddyy10.;
datalines;
1 10/21/2015 20
1 11/10/2015 20
1 11/30/2015 30
2 5/1/2013 20
2 5/20/2013 10
2 6/10/2013 3
;
run;
data temp;
 set temp;
 by patid;
 if first.patid or fill_dt&amp;gt;lag(end_date) then group+1;
run;
data want;
 set temp;
 by group;
 retain date;
 if first.group then do;sum=0;date=fill_dt;end;
 sum+days_sup;
 if last.group;
 format date mmddyy10.;
 keep patid sum date;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jun 2018 12:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468340#M285416</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-06-07T12:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days of supply by fill date while correcting for refills</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468361#M285417</link>
      <description>&lt;P&gt;Thank you ballardw. The solution works perfectly. I always have difficulty with retain and output statements, it is hard to get what I want by playing with them. Any references? Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 13:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468361#M285417</guid>
      <dc:creator>ncy</dc:creator>
      <dc:date>2018-06-07T13:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days of supply by fill date while correcting for refills</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468362#M285418</link>
      <description>&lt;P&gt;Thank you Ksharp. The idea of creating another group indicator is fantastic!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 13:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468362#M285418</guid>
      <dc:creator>ncy</dc:creator>
      <dc:date>2018-06-07T13:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days of supply by fill date while correcting for refills</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468400#M285419</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patid fill_dt : mmddyy10. days_sup;
format fill_dt mmddyy10.;
datalines;
1 10/21/2015 20
1 11/10/2015 20
1 11/30/2015 30
2 5/1/2013 20
2 5/20/2013 10
2 6/10/2013 3
;
run;

data temp;
set have;
by patid;
retain k;
if first.patid then do; grp=0;k=0;end;
if not(fill_dt &amp;lt;= k) then grp+1;
k=intnx('days',fill_dt,days_sup);
drop k;
run;

proc sql;
create table want as
select patid ,fill_dt,sum(days_sup) as sum
from temp
group by patid, grp
having fill_dt=min(fill_dt)
order by patid, fill_dt;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jun 2018 14:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-days-of-supply-by-fill-date-while-correcting-for/m-p/468400#M285419</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-07T14:56:40Z</dc:date>
    </item>
  </channel>
</rss>

