<?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: SAS output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664572#M198575</link>
    <description>&lt;P&gt;yes&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;. sorry . i will ensure this from next time on wards&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jun 2020 07:29:51 GMT</pubDate>
    <dc:creator>JJP1</dc:creator>
    <dc:date>2020-06-24T07:29:51Z</dc:date>
    <item>
      <title>Get the latest record based on col2 column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664407#M198488</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;i have input data as below with columns as date,COL2,COL3,COL4 and COL5. tried using proc sort along with first and last options but not giving desired output.please help.&lt;/P&gt;&lt;PRE&gt;21JAN2020 4 XXX MAMA 1232343443&lt;BR /&gt;21JAN2020 5 XXX MAMA 1232343443&lt;BR /&gt;23JAN2020 10 XXX HAHAHA 1232343443&lt;BR /&gt;23JAN2020 11 XXX HAHAHA 1232343443&lt;BR /&gt;14FEB2020 19 XXX HAHAHA 1232343443&lt;BR /&gt;14FEB2020 21 XXX HAHAHA 1232343443&lt;BR /&gt;23MAR2020 30 XXX MUMUMUM 1232343443&lt;BR /&gt;23MAR2020 31 XXX MUMUMUM 1232343443&lt;BR /&gt;25MAR2020 32 XXX FUFUFUF 1232343443&lt;BR /&gt;25MAR2020 33 XXX FUFUFUF 1232343443&lt;BR /&gt;25MAR2020 37 XXX FUFUFUF 1232343443&lt;BR /&gt;26MAR2020 47 XXX HARHAR 1232343443&lt;BR /&gt;26MAR2020 52 XXX HARHAR 1232343443&lt;BR /&gt;26MAR2020 56 XXX HARHAR 1232343443&lt;BR /&gt;26MAR2020 45 XXX MUMUMUM 1232343443&lt;BR /&gt;26MAR2020 46 XXX MUMUMUM 1232343443&lt;BR /&gt;26MAR2020 54 XXX MUMUMUM 1232343443&lt;BR /&gt;26MAR2020 55 XXX MUMUMUM 1232343443&lt;/PRE&gt;&lt;P&gt;Expecting output as below&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26MAR2020 56 XXX HARHAR 1232343443&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 07:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664407#M198488</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2020-06-24T07:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664411#M198491</link>
      <description>&lt;P&gt;What's your logic for extracting that single record? &lt;BR /&gt;&lt;BR /&gt;In theory this would work but likely will not work on your actual data because the logic doesn't generalize to your actual data.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by date var2 var3 notsorted;
if last.var3 and var3='HRHRHT';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;EDIT: should be last.var3 not last.date.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 17:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664411#M198491</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-23T17:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664440#M198498</link>
      <description>&lt;P&gt;Are COL2 and COL3 the same for all observation of the same date?&lt;/P&gt;
&lt;P&gt;Is col2 the same for all observations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To use first.&amp;lt;var&amp;gt; or lats.&amp;lt;var&amp;gt; you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;(1) data most be sorted by &amp;lt;major varibles&amp;gt; &amp;amp; the &amp;lt;var&amp;gt; as the minor one,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;as in next example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
    by date col2 col3;
run;
data want;
   set have;
     by date col2 col3;
         if first.col3;    /* or if last.col3; */
        .....
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, what was the logic to select net line as wanted:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;26MAR2020	XXX	CCCCCC	123456676&lt;/LI-CODE&gt;
&lt;P&gt;Are you looking for the first observation? the last observation? of a specific date?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If you mean the first observation of the latest date &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;then you can use next codes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* option 1 */
proc sort data=have;
 by descending date /*col2 ? */ col3;
run;
data want;
 set have;
  by descending date col3;
  if _N_ = 1;
run;

/* option 2 */
proc sql noprint;
  create table temp
  as select max(date) as date
                 min(col3) as col3
  from have;
  create table want  
    as select distinct * 
	from have as h,
	        temp as t
	where h.date = t.date and
	         h.col3 = t.col3;
quit;
	
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 18:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664440#M198498</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-23T18:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664555#M198560</link>
      <description>&lt;P&gt;Actually the problem here is all date values and other column values are same except COL3.&lt;/P&gt;&lt;P&gt;Currently if we sort the data and getting the lastobservation based on last.col4 and fetching col3 value that is nothing but&amp;nbsp;JJJJJJJ. But as per correct scenario that col3 is not the last one and i need to arrange the data so that last value will come as 'CCCCCC'. so that i can take last.col4&amp;nbsp;&lt;/P&gt;&lt;P&gt;tried multiple ways but i am getting 'JJJJJJJ'&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 05:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664555#M198560</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2020-06-24T05:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664560#M198564</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/256123"&gt;@JJP1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Actually the problem here is all date values and other column values are same except COL3.&lt;/P&gt;
&lt;P&gt;Currently if we sort the data and getting the lastobservation based on last.col4 and fetching col3 value that is nothing but&amp;nbsp;JJJJJJJ. But as per correct scenario that col3 is not the last one and i need to arrange the data so that last value will come as 'CCCCCC'. so that i can take last.col4&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tried multiple ways but i am getting 'JJJJJJJ'&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't know any alphabet in which multiple Cs are sorted after multiple Js. So please&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;post data that is closer to the data you have&lt;/LI&gt;
&lt;LI&gt;Describe the logic to be used to select the observation you want.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 24 Jun 2020 05:55:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664560#M198564</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-06-24T05:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664569#M198572</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;Actually i have brought in another column. please have a look now with input data(edited the original post)&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 07:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664569#M198572</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2020-06-24T07:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664571#M198574</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/256123"&gt;@JJP1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;Actually i have brought in another column. please have a look now with input data(edited the original post)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Pleaser never ever again edit a post in that way, now all answers already given are completely impossible to understand.&lt;/P&gt;
&lt;P&gt;So, you want to select the observation with highest value in col2?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 07:24:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664571#M198574</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-06-24T07:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664572#M198575</link>
      <description>&lt;P&gt;yes&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;. sorry . i will ensure this from next time on wards&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 07:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664572#M198575</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2020-06-24T07:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Get the latest record based on col2 column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664573#M198576</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select * 
from have
where col2 eq (select max(col2) from have);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jun 2020 07:32:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664573#M198576</guid>
      <dc:creator>sustagens</dc:creator>
      <dc:date>2020-06-24T07:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get the latest record based on col2 column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664574#M198577</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281550"&gt;@sustagens&lt;/a&gt;&amp;nbsp;. i have sorted using proc sort the data based on col2 and got the desired output based on last.col4&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 07:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-latest-record-based-on-col2-column/m-p/664574#M198577</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2020-06-24T07:36:48Z</dc:date>
    </item>
  </channel>
</rss>

