<?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: Calculating days late to refill in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718283#M222262</link>
    <description>&lt;P&gt;Let's do first things first - namely provide working code in the DATA HAVE step (and put it in a SAS code box using the "running man" symbol at the top of every message window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran your DATA HAVE step.&amp;nbsp; Here are the results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2   data temp;
23     input ID1 ID2 Product fill_dt : mmddyy10. days_supply end_dt : mmddyy10.;
24     format fill_dt end_dt mmddyy10.;
25   datalines;

NOTE: Invalid data for Product in line 26 10-10.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+--
26         117 2025 A 12/13/2019 90 3/12/2020
ID1=117 ID2=2025 Product=. fill_dt=12/13/2019 days_supply=90 end_dt=03/12/2020 _ERROR_=1 _N_=1
NOTE: Invalid data for Product in line 27 10-10.
27         117 2025 A 3/10/2020 90 6/8/2020
ID1=117 ID2=2025 Product=. fill_dt=03/10/2020 days_supply=90 end_dt=06/08/2020 _ERROR_=1 _N_=2
NOTE: Invalid data for Product in line 28 10-10.
28         117 2025 A 6/9/2020 90 9/7/2020
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;... and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, perhaps you could point out the differences between what you want and what you got.&amp;nbsp; It is not so evident to me, and I imagine some others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Help us help you.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Feb 2021 15:57:02 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-02-10T15:57:02Z</dc:date>
    <item>
      <title>Calculating days late to refill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718276#M222257</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to calculate the Days Late to Refill by ID1 and the corresponding to each Product.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;BR /&gt;input ID1 ID2 Product fill_dt : mmddyy10. days_supply end_dt : mmddyy10.;&lt;/P&gt;
&lt;P&gt;format fill_dt end_dt mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;117 2025 A 12/13/2019 90 3/12/2020&lt;BR /&gt;117 2025 A 3/10/2020 90 6/8/2020&lt;BR /&gt;117 2025 A 6/9/2020 90 9/7/2020&lt;BR /&gt;117 2025 A 9/8/2020 22 9/30/2020&lt;BR /&gt;117 2025 B 10/22/2019 90 1/20/2020&lt;BR /&gt;117 2025 B 1/21/2020 90 4/20/2020&lt;BR /&gt;117 2025 B 4/14/2020 90 7/13/2020&lt;BR /&gt;117 2025 B 8/6/2020 55 9/30/2020&lt;BR /&gt;117 2025 C 11/26/2019 90 2/24/2020&lt;BR /&gt;117 2025 C 2/25/2020 90 5/25/2020&lt;BR /&gt;117 2025 C 5/26/2020 90 8/24/2020&lt;BR /&gt;117 2025 C 8/31/2020 30 9/30/2020&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a code that I have written:&lt;/P&gt;
&lt;P&gt;data temp_2;&lt;BR /&gt;set temp;&lt;BR /&gt;by ID1 ID2 Product Fill_dt End_Dt;&lt;BR /&gt;if first.ID1 then _iorc_=end_dt;&lt;BR /&gt;else do;&lt;BR /&gt;days=fill_dt-_iorc_; &lt;BR /&gt;_iorc_=end_dt;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the output looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID1 ID2 Product fill_dt days_supply end_dt days&lt;BR /&gt;117 2025 A 12/13/2019 90 3/12/2020 &lt;BR /&gt;117 2025 A 3/10/2020 90 6/8/2020 -2&lt;BR /&gt;117 2025 A 6/9/2020 90 9/7/2020 1&lt;BR /&gt;117 2025 A 9/8/2020 22 9/30/2020 1&lt;BR /&gt;117 2025 B 10/22/2019 90 1/20/2020 -344&lt;BR /&gt;117 2025 B 1/21/2020 90 4/20/2020 1&lt;BR /&gt;117 2025 B 4/14/2020 90 7/13/2020 -6&lt;BR /&gt;117 2025 B 8/6/2020 55 9/30/2020 24&lt;BR /&gt;117 2025 C 11/26/2019 90 2/24/2020 -309&lt;BR /&gt;117 2025 C 2/25/2020 90 5/25/2020 1&lt;BR /&gt;117 2025 C 5/26/2020 90 8/24/2020 1&lt;BR /&gt;117 2025 C 8/31/2020 30 9/30/2020 7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I want it to look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID1 ID2 Product fill_dt days_supply end_dt days&lt;BR /&gt;117 2025 A 12/13/2019 90 3/12/2020 .&lt;BR /&gt;117 2025 A 3/10/2020 90 6/8/2020 -2&lt;BR /&gt;117 2025 A 6/9/2020 90 9/7/2020 1&lt;BR /&gt;117 2025 A 9/8/2020 22 9/30/2020 1&lt;BR /&gt;117 2025 B 10/22/2019 90 1/20/2020 .&lt;BR /&gt;117 2025 B 1/21/2020 90 4/20/2020 1&lt;BR /&gt;117 2025 B 4/14/2020 90 7/13/2020 -6&lt;BR /&gt;117 2025 B 8/6/2020 55 9/30/2020 24&lt;BR /&gt;117 2025 C 11/26/2019 90 2/24/2020 .&lt;BR /&gt;117 2025 C 2/25/2020 90 5/25/2020 1&lt;BR /&gt;117 2025 C 5/26/2020 90 8/24/2020 1&lt;BR /&gt;117 2025 C 8/31/2020 30 9/30/2020 7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance for helping.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 15:36:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718276#M222257</guid>
      <dc:creator>ssitharath0420</dc:creator>
      <dc:date>2021-02-10T15:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating days late to refill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718283#M222262</link>
      <description>&lt;P&gt;Let's do first things first - namely provide working code in the DATA HAVE step (and put it in a SAS code box using the "running man" symbol at the top of every message window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran your DATA HAVE step.&amp;nbsp; Here are the results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2   data temp;
23     input ID1 ID2 Product fill_dt : mmddyy10. days_supply end_dt : mmddyy10.;
24     format fill_dt end_dt mmddyy10.;
25   datalines;

NOTE: Invalid data for Product in line 26 10-10.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+--
26         117 2025 A 12/13/2019 90 3/12/2020
ID1=117 ID2=2025 Product=. fill_dt=12/13/2019 days_supply=90 end_dt=03/12/2020 _ERROR_=1 _N_=1
NOTE: Invalid data for Product in line 27 10-10.
27         117 2025 A 3/10/2020 90 6/8/2020
ID1=117 ID2=2025 Product=. fill_dt=03/10/2020 days_supply=90 end_dt=06/08/2020 _ERROR_=1 _N_=2
NOTE: Invalid data for Product in line 28 10-10.
28         117 2025 A 6/9/2020 90 9/7/2020
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;... and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, perhaps you could point out the differences between what you want and what you got.&amp;nbsp; It is not so evident to me, and I imagine some others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Help us help you.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 15:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718283#M222262</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-10T15:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating days late to refill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718293#M222268</link>
      <description>&lt;P&gt;As mentioned above, you have a couple formatting issues. Nonetheless, this should provide you your answer, but it depends on the sorting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input ID1 ID2 Product $1. fill_dt :mmddyy10. days_supply end_dt :mmddyy10.;
format fill_dt end_dt mmddyy10.;
datalines;
117 2025 A 12/13/2019 90 3/12/2020
117 2025 A 3/10/2020 90 6/8/2020
117 2025 A 6/9/2020 90 9/7/2020
117 2025 A 9/8/2020 22 9/30/2020
117 2025 B 10/22/2019 90 1/20/2020
117 2025 B 1/21/2020 90 4/20/2020
117 2025 B 4/14/2020 90 7/13/2020
117 2025 B 8/6/2020 55 9/30/2020
117 2025 C 11/26/2019 90 2/24/2020
117 2025 C 2/25/2020 90 5/25/2020
117 2025 C 5/26/2020 90 8/24/2020
117 2025 C 8/31/2020 30 9/30/2020
;
run;

proc sort data = temp;
	by id1 id2 product fill_dt;
run;

data want;
	set temp;
	by id1 id2 product fill_dt;
		lag_end_dt = lag(end_dt);
		if first.product then call missing(lag_end_dt);
		if not missing(lag_end_dt) then do;
			days = intck("days", lag_end_dt, fill_dt);
		end;
	format lag_end_dt mmddyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="maguiremq_0-1612974139591.png"&gt;&lt;img src="https://communities.sas.com/skins/images/E0BB18E7DAA53C21BC28740CEA0E38DA/responsive_peak/images/image_not_found.png" alt="maguiremq_0-1612974139591.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 16:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718293#M222268</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-02-10T16:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating days late to refill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718312#M222282</link>
      <description>&lt;P&gt;Thank you! It worked!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 16:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718312#M222282</guid>
      <dc:creator>ssitharath0420</dc:creator>
      <dc:date>2021-02-10T16:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating days late to refill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718318#M222286</link>
      <description>&lt;P&gt;Great, I'm glad it helped. Please mark the response as the correct solution so it can help others in the future.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 17:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-days-late-to-refill/m-p/718318#M222286</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-02-10T17:20:37Z</dc:date>
    </item>
  </channel>
</rss>

