<?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: calculate difference between 2 dates in same group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663661#M198175</link>
    <description>&lt;P&gt;Please post the same question only once.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest that "we" answer only &lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/td-p/663652" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Sat, 20 Jun 2020 00:44:02 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-06-20T00:44:02Z</dc:date>
    <item>
      <title>How to calculate days between 2 dates in separate rows and same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663652#M198154</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MY data looks like this. It's ordered by ID and date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;BAN&lt;/TD&gt;&lt;TD&gt;col_date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100023&lt;/TD&gt;&lt;TD&gt;05-May-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100023&lt;/TD&gt;&lt;TD&gt;04-Jun-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123455&lt;/TD&gt;&lt;TD&gt;05-May-20&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need an output like below where the date from the second row becomes a variable in the first row and so on. Grouping has to be by ID. if there is only one record for the ID then the next date would be blank. ID could have single or multiple rows&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;BAN&lt;/TD&gt;&lt;TD&gt;col_date&lt;/TD&gt;&lt;TD&gt;next_date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100023&lt;/TD&gt;&lt;TD&gt;05-May-20&lt;/TD&gt;&lt;TD&gt;04-Jun-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100023&lt;/TD&gt;&lt;TD&gt;04-Jun-20&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123455&lt;/TD&gt;&lt;TD&gt;05-May-20&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried sorting the data by ID descending date and the using the dif function to get the difference between dates but it's not working. What am i doing wrong? direction is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Data test;&lt;BR /&gt;set Non;&lt;BR /&gt;by ID ;&lt;BR /&gt;Difference = Dif(col_date);&lt;BR /&gt;run;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 00:04:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663652#M198154</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-06-20T00:04:09Z</dc:date>
    </item>
    <item>
      <title>calculate difference between 2 dates in same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663653#M198174</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MY data looks like this. It's ordered by ID and date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;BAN&lt;/TD&gt;&lt;TD&gt;col_date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100023&lt;/TD&gt;&lt;TD&gt;05-May-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100023&lt;/TD&gt;&lt;TD&gt;04-Jun-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123455&lt;/TD&gt;&lt;TD&gt;05-May-20&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need an output like below where the date from the second row becomes a variable in the first row and so on. Grouping has to be by ID. if there is only one record for the ID then the next date would be blank. ID could have single or multiple rows&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;BAN&lt;/TD&gt;&lt;TD&gt;col_date&lt;/TD&gt;&lt;TD&gt;next_date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100023&lt;/TD&gt;&lt;TD&gt;05-May-20&lt;/TD&gt;&lt;TD&gt;04-Jun-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100023&lt;/TD&gt;&lt;TD&gt;04-Jun-20&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123455&lt;/TD&gt;&lt;TD&gt;05-May-20&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried sorting the data by ID descending date and the using the dif function to get the difference between dates but it's not working. What am i doing wrong? direction is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Data test;&lt;BR /&gt;set Non;&lt;BR /&gt;by ID ;&lt;BR /&gt;Difference = Dif(col_date);&lt;BR /&gt;run;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 00:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663653#M198174</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-06-20T00:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference between 2 dates in same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663661#M198175</link>
      <description>&lt;P&gt;Please post the same question only once.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest that "we" answer only &lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/td-p/663652" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 00:44:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663661#M198175</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-20T00:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate days between 2 dates in separate rows and same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663663#M198160</link>
      <description>&lt;P&gt;Something like below should do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=want;
  by id descending col_date;
run;

data want;
  set want;
  by id;
  format next_date date9.;
  next_date=lag(col_date);
  if first.id then call missing(next_date);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Jun 2020 00:50:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663663#M198160</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-20T00:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate days between 2 dates in separate rows and same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663669#M198166</link>
      <description>&lt;P&gt;If you have a license to SAS/ETS, use &lt;STRONG&gt;proc expand&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc expand data=have out=want;
by BAN;
convert col_date=next_date / transformout=(lead);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that, as a bonus, the format associated with col_date will also be given to next_date by the procedure.&amp;nbsp; &lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 04:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663669#M198166</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-06-20T04:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate days between 2 dates in separate rows and same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663676#M198170</link>
      <description>Thanks Patrick, never seen proc expand but it works...it gave me the output...&lt;BR /&gt;&lt;BR /&gt;the datastep example you gave was faster but it doesn't have the desired output&lt;BR /&gt;&lt;BR /&gt;I got the below instead.. i will try again tomorrow since the account is locked. maybe the sort is wrong? Thank you again&lt;BR /&gt;&lt;BR /&gt;BAN col_date next_date&lt;BR /&gt;100023 05-May-20 .&lt;BR /&gt;100023 04-Jun-20 05-May-20&lt;BR /&gt;123455 05-May-20 .&lt;BR /&gt;</description>
      <pubDate>Sat, 20 Jun 2020 05:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663676#M198170</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-06-20T05:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference between 2 dates in same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663683#M198176</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Please post the same question only once.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest that "we" answer only &lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/td-p/663652" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Merged them.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 07:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663683#M198176</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-20T07:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate days between 2 dates in separate rows and same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663684#M198177</link>
      <description>&lt;P&gt;Use a "look-ahead":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  have
  have (firstobs=2 rename=(ban=_ban col_date=next_date))
;
if ban ne _ban then next_date = .;
drop _ban;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 07:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663684#M198177</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-20T07:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate days between 2 dates in separate rows and same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663707#M198188</link>
      <description>Thank you Kurt,&lt;BR /&gt;&lt;BR /&gt;This works!! i got the result i wanted&lt;BR /&gt;&lt;BR /&gt;BAN col_date next_date&lt;BR /&gt;104175 28-May-20 29-May-20&lt;BR /&gt;104175 29-May-20 05-Jun-20&lt;BR /&gt;104175 05-Jun-20 15-Jun-20&lt;BR /&gt;104175 15-Jun-20 .&lt;BR /&gt;146960 05-May-20 .&lt;BR /&gt;</description>
      <pubDate>Sat, 20 Jun 2020 15:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663707#M198188</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-06-20T15:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate days between 2 dates in separate rows and same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663710#M198189</link>
      <description>Thanks Patrick, it did work. I missed the descending sort at first. Appreciate it.</description>
      <pubDate>Sat, 20 Jun 2020 15:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-days-between-2-dates-in-separate-rows-and-same/m-p/663710#M198189</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-06-20T15:22:58Z</dc:date>
    </item>
  </channel>
</rss>

