<?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: update the date duration as Start and End in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586018#M167235</link>
    <description>&lt;P&gt;You should seriously consider storing the result in a string and not a number, as with a number 2.1 equals 2.10.&lt;/P&gt;</description>
    <pubDate>Wed, 04 Sep 2019 06:52:09 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-09-04T06:52:09Z</dc:date>
    <item>
      <title>update the date duration as Start and End</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586006#M167226</link>
      <description>&lt;P&gt;Dear Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to calculate the date duration in the below-given format.&lt;/P&gt;&lt;P&gt;Let me share the sample dataset for a clear view.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Id r_date :mmddyy10. e_date :mmddyy10.;
format r_date e_date mmddyy10.;
cards;
101 05/18/2001 09/25/2002
101 09/26/2002 12/12/2003
101 12/13/2003 05/04/2004
108 06/06/1995 08/12/1996
108 08/11/1996 07/10/1999
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For this data set, I need to process the date duration in the given method.&lt;/P&gt;&lt;P&gt;Expected output.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas dbt.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32194iDE9CA423878B568D/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas dbt.jpg" alt="sas dbt.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note : The value of &lt;STRONG&gt;Start_dur&lt;/STRONG&gt; in each &lt;EM&gt;minimum&lt;/EM&gt; &lt;STRONG&gt;R_date&lt;/STRONG&gt; of IDs is always &lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Each &lt;STRONG&gt;E_dur&lt;/STRONG&gt;&amp;nbsp;will calculate the duration of the &lt;EM&gt;minimum&lt;/EM&gt; &lt;STRONG&gt;R_date&lt;/STRONG&gt; of corresponding IDs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest some ideas to solve the task.&lt;/P&gt;&lt;P&gt;Thanks in Advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 06:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586006#M167226</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2019-09-04T06:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: update the date duration as Start and End</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586011#M167230</link>
      <description>&lt;P&gt;I'm not sure, I get this completely, though here's a shot. I don't understand why End_Dur should be three in the last obs in the ID=101 group though?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    if 0 then set have;
    Start_Dur=0;
    do until (last.id);
        set have;
        by id;
        End_Dur=Start_Dur+round(intck('day', r_date, e_date)/365.25, .1);
        output;
        Start_Dur=End_Dur;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Id      r_date          e_date       Start_Dur End_Dur&lt;BR /&gt;101	05/18/2001	09/25/2002   0	       1.4
101	09/26/2002	12/12/2003   1.4       2.6
101	12/13/2003	05/04/2004   2.6       3
108	06/06/1995	08/12/1996   0	       1.2
108	08/11/1996	07/10/1999   1.2       4.1&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Sep 2019 11:06:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586011#M167230</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-04T11:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: update the date duration as Start and End</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586012#M167231</link>
      <description>&lt;P&gt;Maybe i need more coffee to understand this, but please explain how to calculate the values of End_Dur.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 06:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586012#M167231</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-09-04T06:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: update the date duration as Start and End</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586016#M167233</link>
      <description>&lt;P&gt;It takes a little trickery to build the number, but here we go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Id r_date :mmddyy10. e_date :mmddyy10.;
format r_date e_date yymmddd10.;
cards;
101 05/18/2001 09/25/2002
101 09/26/2002 12/12/2003
101 12/13/2003 05/04/2004
108 06/06/1995 08/12/1996
108 08/11/1996 07/10/1999
run;

data want;
set have;
by id;
retain start_dur end_dur start_date;
format start_dur end_dur best5.;
if first.id
then do;
  start_dur = 0;
  start_date = r_date;
end;
else do;
  start_dur = end_dur;
end;
dur = intck('month',start_date,e_date,'c');
end_dur = input(catx('.',put(int(dur/12),3.),put(mod(dur,12),2.)),5.);
drop start_date dur;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                                   start_
 Id        r_date        e_date     dur      end_dur

101    2001-05-18    2002-09-25        0        1.4 
101    2002-09-26    2003-12-12      1.4        2.6 
101    2003-12-13    2004-05-04      2.6       2.11 
108    1995-06-06    1996-08-12        0        1.2 
108    1996-08-11    1999-07-10      1.2        4.1 
&lt;/PRE&gt;
&lt;P&gt;Mind that such a number isn't much good for further use, as 2.11 is smaller than 2.2.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 06:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586016#M167233</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-04T06:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: update the date duration as Start and End</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586017#M167234</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Maybe i need more coffee to understand this, but please explain how to calculate the values of End_Dur.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The decimals are the number of months, so you get a meaningless result when stored as a number (because 0.10 is the same as 0.1).&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 06:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586017#M167234</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-04T06:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: update the date duration as Start and End</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586018#M167235</link>
      <description>&lt;P&gt;You should seriously consider storing the result in a string and not a number, as with a number 2.1 equals 2.10.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 06:52:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586018#M167235</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-04T06:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: update the date duration as Start and End</title>
      <link>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586088#M167273</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Id r_date :mmddyy10. e_date :mmddyy10.;
dif=round(yrdif(r_date,e_date,'age'),.1);
format r_date e_date yymmddd10.;
cards;
101 05/18/2001 09/25/2002
101 09/26/2002 12/12/2003
101 12/13/2003 05/04/2004
108 06/06/1995 08/12/1996
108 08/11/1996 07/10/1999
;
run;
data want;
 set have;
 by id;
 if first.id then end_dur=0;
 end_dur+dif;
 start_dur=lag(end_dur);
 if first.id then start_dur=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Sep 2019 12:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/update-the-date-duration-as-Start-and-End/m-p/586088#M167273</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-09-04T12:37:06Z</dc:date>
    </item>
  </channel>
</rss>

