<?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 Difference between dates across rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-dates-across-rows/m-p/475292#M122206</link>
    <description>&lt;P&gt;Hi guys, I thought below would manage calculating the difference between time periods&amp;nbsp;across each rows. But I&amp;nbsp;wind up with not only huge but negative numbers. Please help correcting this syntax out. What I want is about 132 days difference&amp;nbsp;between two rows (07022002 and 11142002) &amp;nbsp;in the second row instead 4120000 and so forth so&amp;nbsp;on for&amp;nbsp;the rest of the rows.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wrong output.png" style="width: 278px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21559iE168C385286D9216/image-size/large?v=v2&amp;amp;px=999" role="button" title="wrong output.png" alt="wrong output.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data diff_date;
input Date_Visit $ ID $;
cards;
07022002 83
11142002 83
05152003 83
11042003 83
05042004 83
11102004 83
05032005 83
11012005 83
06062006 83
;

data b; set diff_date;  
/*format date_visit 9.;*/
by child_id;
retain r_date;
r_date=lag(date_visit);
if not first.child_id then do;
diff_visit=date_visit-r_date;
end;
drop r_:;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Jul 2018 18:49:36 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2018-07-03T18:49:36Z</dc:date>
    <item>
      <title>Difference between dates across rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-dates-across-rows/m-p/475292#M122206</link>
      <description>&lt;P&gt;Hi guys, I thought below would manage calculating the difference between time periods&amp;nbsp;across each rows. But I&amp;nbsp;wind up with not only huge but negative numbers. Please help correcting this syntax out. What I want is about 132 days difference&amp;nbsp;between two rows (07022002 and 11142002) &amp;nbsp;in the second row instead 4120000 and so forth so&amp;nbsp;on for&amp;nbsp;the rest of the rows.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wrong output.png" style="width: 278px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21559iE168C385286D9216/image-size/large?v=v2&amp;amp;px=999" role="button" title="wrong output.png" alt="wrong output.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data diff_date;
input Date_Visit $ ID $;
cards;
07022002 83
11142002 83
05152003 83
11042003 83
05042004 83
11102004 83
05032005 83
11012005 83
06062006 83
;

data b; set diff_date;  
/*format date_visit 9.;*/
by child_id;
retain r_date;
r_date=lag(date_visit);
if not first.child_id then do;
diff_visit=date_visit-r_date;
end;
drop r_:;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 18:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-dates-across-rows/m-p/475292#M122206</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-07-03T18:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between dates across rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-dates-across-rows/m-p/475295#M122208</link>
      <description>&lt;P&gt;11142002 is not a date, but a 8-digit number (by now - more than 300 posts here - you should know that). Store dates as SAS date values, and use intck() to get distances in time.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 18:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-dates-across-rows/m-p/475295#M122208</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-03T18:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between dates across rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-dates-across-rows/m-p/475303#M122209</link>
      <description>&lt;P&gt;It would take a few changes here and there, starting with how you read in the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data diff_date;
input Date_Visit mmddyy8.  ID $;
cards;
07022002 83
11142002 83
05152003 83
11042003 83
05042004 83
11102004 83
05032005 83
11012005 83
06062006 83
;

data want; 
set diff_date;  
by id;
diff_visit = dif(date_visit);
if first.id then diff_visit = .;
run; &lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Jul 2018 19:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-dates-across-rows/m-p/475303#M122209</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-03T19:14:14Z</dc:date>
    </item>
  </channel>
</rss>

