<?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 Help with date interval in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Help-with-date-interval/m-p/685000#M24264</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to use a date variable to calculate the difference between two dates. I am trying to see the difference between the first and last observation for a given ID, but sometimes there are more than 2 observations per individual. Take the sample data below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DateStamp&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01AUG2020&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07SEP2020&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01AUG2020&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08AUG2020&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11SEP2020&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;05JUN2020&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01AUG2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to end up with a variable that is the date difference between the first ID entry and the last ID entry (for example, for ID #1, the date variable would be the difference between September 7 and August 1, for ID #2, the date variable would be the difference between August 1 and September 11, etc).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone help me with this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 18 Sep 2020 15:18:09 GMT</pubDate>
    <dc:creator>marleeakerson</dc:creator>
    <dc:date>2020-09-18T15:18:09Z</dc:date>
    <item>
      <title>Help with date interval</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-date-interval/m-p/685000#M24264</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to use a date variable to calculate the difference between two dates. I am trying to see the difference between the first and last observation for a given ID, but sometimes there are more than 2 observations per individual. Take the sample data below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DateStamp&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01AUG2020&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07SEP2020&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01AUG2020&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08AUG2020&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11SEP2020&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;05JUN2020&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01AUG2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to end up with a variable that is the date difference between the first ID entry and the last ID entry (for example, for ID #1, the date variable would be the difference between September 7 and August 1, for ID #2, the date variable would be the difference between August 1 and September 11, etc).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone help me with this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 15:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-date-interval/m-p/685000#M24264</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-09-18T15:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with date interval</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-date-interval/m-p/685005#M24265</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID                DateStamp :date9.;
format datestamp date9.;
cards;
1                 01AUG2020

1                 07SEP2020

2                 01AUG2020

2                 08AUG2020

2                 11SEP2020

3                 05JUN2020

3                 01AUG2020
;

proc sql;
 create table want as
 select id, range(datestamp) as datediff
 from have
 group by id;
quit;

/*Or*/

proc summary data=have nway;
 class id;
 var datestamp;
 output out=want range=Datediff;
 format datestamp;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2020 15:26:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-date-interval/m-p/685005#M24265</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-09-18T15:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with date interval</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-date-interval/m-p/685187#M24277</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; And, in the interest of completeness.... if all you need is a report of the difference, you can get that directly from the original data (HAVE) without creating a second table using either PROC REPORT or PROC TABULATE:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1600524494293.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49562iA2B9B55FE9AFE2B3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1600524494293.png" alt="Cynthia_sas_0-1600524494293.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Using this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc report data=have;
  title 'proc report solution';
  column id datestamp,range;
  define id / group;
  define datestamp/analysis ;
  define range / 'Difference' f=6.0;
run;

proc tabulate data=have f=6.0;
  title 'proc tabulate solution';
  class id;
  var datestamp;
  table id=' ',
        datestamp*range='Difference'/Box=ID;
run;
title;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 14:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-date-interval/m-p/685187#M24277</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-09-19T14:10:16Z</dc:date>
    </item>
  </channel>
</rss>

