<?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: Group identical ids and indicate first and last date of an incident per id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/366047#M275147</link>
    <description>Great solution for this problem, thanks a lot !</description>
    <pubDate>Mon, 12 Jun 2017 04:07:52 GMT</pubDate>
    <dc:creator>AnnaNZ</dc:creator>
    <dc:date>2017-06-12T04:07:52Z</dc:date>
    <item>
      <title>Group identical ids and indicate first and last date of an incident per id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/365577#M275143</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with many identical IDs, which were taken up at different times (datetime 18).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to know the earlierst and the last time that an ID was taken up ( and calculate the timeinterval).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So some REFER_ID appeas on multiple different times (LAT_UPDT_DT) as indicted below in red.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The aim is to calculate the timedifference between the fist time and the last time they appear.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9287iC001F7D98BD4453F/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sort data = main_vic; by REFER_ID ;
run;

proc sql;
  create table want as
    select min(LST_UPDT_DT) as min_date format=datetime18.,
                 max(LST_UPDT_DT) as max_date format=datetime18.
             from main_vic;
quit;&lt;/PRE&gt;&lt;P&gt;This of course gives me only the first and the last date of all REFER_ID&lt;/P&gt;&lt;P&gt;How can I group &lt;SPAN&gt;REFER_ID so &amp;nbsp;that I always receive the first and last visit of that REFER_ID?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I tried to add a by statement, but was not sucessful.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any ideas are highly appreaciated.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 02:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/365577#M275143</guid>
      <dc:creator>AnnaNZ</dc:creator>
      <dc:date>2017-06-09T02:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Group identical ids and indicate first and last date of an incident per id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/365578#M275144</link>
      <description>&lt;P&gt;Please try the below code, it is untested but should work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;also included the difference in days and hours&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=have ;
class refer_id;
var lst_updt_dt;
output out=want min=min max=max;
run;

data want2;
set want;
diffinhours=(max-min)/3600;
diffindays=(max-min)/86400;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2017 02:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/365578#M275144</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-06-09T02:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: Group identical ids and indicate first and last date of an incident per id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/365581#M275145</link>
      <description>&lt;P&gt;Something like this. I took a similar example instead of date time. I have used somenum&lt;/P&gt;
&lt;PRE&gt;data abc;
input id someotherval $ somenum;
datalines;
1 a 20
1 b 30
1 c 40
2 a 40
2 a 50
2 a 45
;
run;

proc sql;&lt;BR /&gt;select a.*, max(somenum)-min(somenum) as diff from abc a&lt;BR /&gt;group by id;&lt;BR /&gt;
;&lt;BR /&gt;quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 02:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/365581#M275145</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-09T02:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Group identical ids and indicate first and last date of an incident per id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/365655#M275146</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc;
input id someotherval $ somenum;
datalines;
1 a 20
1 b 30
1 c 40
2 a 40
2 a 50
2 a 45
;
run;

proc sql;
select a.*, range(somenum) as diff from abc as a
group by id;
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2017 13:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/365655#M275146</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-09T13:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: Group identical ids and indicate first and last date of an incident per id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/366047#M275147</link>
      <description>Great solution for this problem, thanks a lot !</description>
      <pubDate>Mon, 12 Jun 2017 04:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-identical-ids-and-indicate-first-and-last-date-of-an/m-p/366047#M275147</guid>
      <dc:creator>AnnaNZ</dc:creator>
      <dc:date>2017-06-12T04:07:52Z</dc:date>
    </item>
  </channel>
</rss>

