<?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: find first id and date in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/474618#M30785</link>
    <description>&lt;P&gt;The way your data is sorted you're looking for the last. Is your data sort important and verified or do you need to verify it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; 
by id date;
run;

data want;
set have;
by id;
if first.id;
dif = predicted-total;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Documentation references:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=n138da4gme3zb7n1nifpfhqv7clq.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=n138da4gme3zb7n1nifpfhqv7clq.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They have some good pictures that illustrate how BY groups work in the documentation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169082"&gt;@hk2013&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
input ID   Date total predicted;
cards;
1              6/24/18    200    250
1             6/30/18    200    270
1              6/18/20    200   230 
2               5/24/18     160   200
2             5/27/18     160   210
2             5/22/18     160   170
3          5/20/18     300   450
3           5/14/18     300   400
3            5/4/18     300     425
;&lt;/PRE&gt;
&lt;P&gt;i want to pick the first date for each ID and subtract that date and IDs Predicted&amp;nbsp; from Total&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 30 Jun 2018 01:26:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-06-30T01:26:16Z</dc:date>
    <item>
      <title>find first id and date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/474615#M30782</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data one;
input ID   Date total predicted;
cards;
1              6/24/18    200    250
1             6/30/18    200    270
1              6/18/20    200   230 
2               5/24/18     160   200
2             5/27/18     160   210
2             5/22/18     160   170
3          5/20/18     300   450
3           5/14/18     300   400
3            5/4/18     300     425
;&lt;/PRE&gt;&lt;P&gt;i want to pick the first date for each ID and subtract that date and IDs Predicted&amp;nbsp; from Total&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Jun 2018 01:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/474615#M30782</guid>
      <dc:creator>hk2013</dc:creator>
      <dc:date>2018-06-30T01:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: find first id and date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/474616#M30783</link>
      <description>&lt;P&gt;Show us the desired result.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Jun 2018 01:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/474616#M30783</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-30T01:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: find first id and date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/474617#M30784</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;result would look like this 
ID             Date       total  Predicted   diff
1              6/18/20    200    230           -30
2             5/22/18     160   170            -10
3            5/4/18     300     425           -125&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Sat, 30 Jun 2018 01:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/474617#M30784</guid>
      <dc:creator>hk2013</dc:creator>
      <dc:date>2018-06-30T01:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: find first id and date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/474618#M30785</link>
      <description>&lt;P&gt;The way your data is sorted you're looking for the last. Is your data sort important and verified or do you need to verify it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; 
by id date;
run;

data want;
set have;
by id;
if first.id;
dif = predicted-total;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Documentation references:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=n138da4gme3zb7n1nifpfhqv7clq.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=n138da4gme3zb7n1nifpfhqv7clq.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They have some good pictures that illustrate how BY groups work in the documentation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169082"&gt;@hk2013&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
input ID   Date total predicted;
cards;
1              6/24/18    200    250
1             6/30/18    200    270
1              6/18/20    200   230 
2               5/24/18     160   200
2             5/27/18     160   210
2             5/22/18     160   170
3          5/20/18     300   450
3           5/14/18     300   400
3            5/4/18     300     425
;&lt;/PRE&gt;
&lt;P&gt;i want to pick the first date for each ID and subtract that date and IDs Predicted&amp;nbsp; from Total&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Jun 2018 01:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/474618#M30785</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-30T01:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: find first id and date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/475000#M30815</link>
      <description>&lt;P&gt;This code should give you the results you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data two (drop=temp);&lt;BR /&gt;set one;&lt;BR /&gt;&amp;nbsp;by ID;&lt;BR /&gt;&amp;nbsp;retain temp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;if first.id then temp=total;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;else if last.id then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; diff=temp-predicted;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 17:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/find-first-id-and-date/m-p/475000#M30815</guid>
      <dc:creator>jebjur</dc:creator>
      <dc:date>2018-07-02T17:58:13Z</dc:date>
    </item>
  </channel>
</rss>

