<?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: Last Observation using multiple variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/351179#M63892</link>
    <description>&lt;P&gt;Thank you for yourswift help with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Much appreciated&lt;/P&gt;</description>
    <pubDate>Wed, 19 Apr 2017 07:55:31 GMT</pubDate>
    <dc:creator>Stretlow</dc:creator>
    <dc:date>2017-04-19T07:55:31Z</dc:date>
    <item>
      <title>Last Observation using multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350794#M63856</link>
      <description>&lt;P&gt;Hi there!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i can see similar questions have been asked on the board before however i cant seem to figure out an answer to my problem so apologies if it has been covered and i've missed it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with multiple variables 3 of which are numeric unique identifiers and one is a date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A sample of what it looks like could be this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AccountNumber1 &amp;nbsp;PNumber SNumber Date&lt;/P&gt;
&lt;P&gt;112335 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2233 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 124 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/01/2017&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;112335 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2233 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 124 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 06/01/2017&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;112335 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;126 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 06/01/2017&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;112335 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;126 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07/01/2017&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;112335 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2233 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 124 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07/01/2017&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;112257 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2234 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 124 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/01/2017&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;etc.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What im looking to find the last observation by checking the other 3 numeric variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So from the&amp;nbsp;above sample&amp;nbsp;the output would be&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;112335 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2233 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 124 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07/01/2017&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;112335 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;126 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07/01/2017&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;112257 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2234 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 124 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/01/2017&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Im sure the data needs to be sorted by the three variables first but im a little stuck from there on.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any help greatly appeicated.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Stret&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 12:00:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350794#M63856</guid>
      <dc:creator>Stretlow</dc:creator>
      <dc:date>2017-04-18T12:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: Last Observation using multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350806#M63857</link>
      <description>&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data A;
  Infile Datalines Missover;
  Input AccountNumber1  PNumber SNumber Date:DDMMYY10.;
  Format Date Date9.;
  Datalines;
112335                  2233         124         01/01/2017
112335                  2233         124         06/01/2017
112335                  1111          126         06/01/2017
112335                  1111          126         07/01/2017
112335                  2233         124         07/01/2017
112257                  2234         124         01/01/2017
;

Proc SQL;
  Create Table Want As
    Select AccountNumber1,PNumber,SNumber,Max(Date) As Date Format=Date9.
	From A
	Group By AccountNumber1,PNumber,SNumber;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2017 12:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350806#M63857</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2017-04-18T12:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Last Observation using multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350807#M63858</link>
      <description>&lt;P&gt;Hi You could use Proc SQL and find the maximum value for the date within a group, like so:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards;
  input
    AccountNumber1  PNumber SNumber Date : mmddyy.
  ;
  format date date9.;
  cards;
112335 2233 124 01/01/2017
112335 2233 124 06/01/2017
112335 1111 126 06/01/2017
112335 1111 126 07/01/2017
112335 2233 124 07/01/2017
112257 2234 124 01/01/2017
;

proc sql;
  select
    AccountNumber1
    , PNumber
    , SNumber
    , max(Date) as lastDate format=date9.
    , count(*) as nRows
  from
    have
  group by
    AccountNumber1
    , PNumber
    , SNumber
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 12:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350807#M63858</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-04-18T12:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Last Observation using multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350835#M63860</link>
      <description>&lt;PRE&gt;proc sort data=have;
  by accountnumber1 pnumber snumber date;
run;
data want;
  set have;
  by accountnumber1 pnumber snumber;
  if last.accountnumber1 then output;
run;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2017 13:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350835#M63860</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-18T13:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Last Observation using multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350882#M63864</link>
      <description>&lt;P&gt;Solution chosen could well depend on whether there are other variables you need along with that specific record.&lt;/P&gt;
&lt;P&gt;If not here's yet another solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=have nway;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;class AccountNumber1 &amp;nbsp;PNumber SNumber;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var date;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output out=want (drop=_:) max =;&lt;/P&gt;
&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 14:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350882#M63864</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-18T14:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Last Observation using multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350893#M63866</link>
      <description>&lt;P&gt;If you want all unique combinations of the three variables that occur in the data then you need to just test the LAST. variable for the last id variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
  by accountnumber1 pnumber snumber date;
run;
data want;
  set have;
  by accountnumber1 pnumber snumber;
  if last.snumber ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2017 15:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/350893#M63866</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-18T15:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Last Observation using multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/351176#M63891</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;data _null_;&lt;BR /&gt;if (_n_ = 1) then do;&lt;BR /&gt;if 0 then set have;&lt;BR /&gt;declare hash myhash(dataset: "have", duplicate: "r", ordered:'a');&lt;BR /&gt;&amp;nbsp;rc = myhash.definekey('AccountNumber1','PNumber','SNumber');&lt;BR /&gt;&amp;nbsp;rc = myhash.definedata('AccountNumber1','PNumber','SNumber','Date');&lt;BR /&gt;myhash.definedone();&lt;BR /&gt;end;&lt;BR /&gt;rc = myhash.output(dataset:"want");&lt;BR /&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2017 07:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/351176#M63891</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-04-19T07:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Last Observation using multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/351179#M63892</link>
      <description>&lt;P&gt;Thank you for yourswift help with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Much appreciated&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2017 07:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Last-Observation-using-multiple-variables/m-p/351179#M63892</guid>
      <dc:creator>Stretlow</dc:creator>
      <dc:date>2017-04-19T07:55:31Z</dc:date>
    </item>
  </channel>
</rss>

