<?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 three rows in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236027#M14705</link>
    <description>&lt;P&gt;Sort in the reverse order. create a record count variable and pick first 3. to remove duplicates using proc sort.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Nov 2015 17:08:24 GMT</pubDate>
    <dc:creator>ndp</dc:creator>
    <dc:date>2015-11-23T17:08:24Z</dc:date>
    <item>
      <title>Last three rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236022#M14704</link>
      <description>&lt;P&gt;3710 16669129019 20110923 016669129019X99 3710 16669129019 20120927 016669129019X99 3710 16669129019 20121007 016669129019X99 3711 16129019 20110923 016669129019X99 3711 669129019 20120927 016669129019X99 3711 1666912 20121007 016669129019X99 3711 1666912 20121009 016669129019X99 3711 1666912 20121109 016669129019X99 How do we take a record that is last three records, based on date (the last record is always is the max date) if the last three records have the same date, choose only one record?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 16:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236022#M14704</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2015-11-23T16:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Last three rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236027#M14705</link>
      <description>&lt;P&gt;Sort in the reverse order. create a record count variable and pick first 3. to remove duplicates using proc sort.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 17:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236027#M14705</guid>
      <dc:creator>ndp</dc:creator>
      <dc:date>2015-11-23T17:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Last three rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236040#M14706</link>
      <description>&lt;P&gt;I would suggest this, especially if your dataset is large so that you would be hesitant to read, let alone sort it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
if 0 then set have nobs=n;
call symputx('n',n-2);
stop;
run;

data want;
set have(firstobs=&amp;amp;n);
by date;
if last.date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This&amp;nbsp;assumes that HAVE is sorted by variable DATE (and that this is the date variable you refer to). You didn't actually specify what to do if only two of the last three records have the same date. In this situation the above program would select the second observation of the date BY-group with two elements (and, of course, the observation from the other BY group). The data-_null_ step stores the number of observations in HAVE &lt;EM&gt;minus two&lt;/EM&gt; in macro variable N, in order to let the second data step start reading at the last but two observation.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 18:03:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236040#M14706</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-23T18:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Last three rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236050#M14707</link>
      <description>&lt;P&gt;Here is another solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;infile cards dsd;&lt;BR /&gt;informat one $4. two $11. date yymmdd8. three $15.;&lt;BR /&gt;format one $4. two $11. date yymmddn8. three $15.;&lt;BR /&gt;input one$ two$ date$ three$;&lt;BR /&gt;cards;&lt;BR /&gt;3710,16669129019,20110923,016669129019X99 &lt;BR /&gt;3710,16669129019,20120927,016669129019X99 &lt;BR /&gt;3710,16669129019,20121007,016669129019X99 &lt;BR /&gt;3711,16129019,20110923,016669129019X99 &lt;BR /&gt;3711,669129019,20120927,016669129019X99 &lt;BR /&gt;3711,1666912,20121007,016669129019X99 &lt;BR /&gt;3711,1666912,20121009,016669129019X99 &lt;BR /&gt;3711,1666912,20121109,016669129019X99&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc sort data=have;by descending date;&lt;BR /&gt;&lt;BR /&gt;data count;&lt;BR /&gt;set have;&lt;BR /&gt;count + 1;&lt;BR /&gt;if count &amp;lt; 4 then output count;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data=count out=want (drop=count) nodupkey;by date;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 18:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236050#M14707</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-11-23T18:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: Last three rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236073#M14708</link>
      <description>data count;&lt;BR /&gt;set have;&lt;BR /&gt;count + 1;&lt;BR /&gt;if count &amp;lt; 4 then output count;&lt;BR /&gt;else stop; /*this will stop SAS from reading in the whole dataset, even though you only need the first 3. Also, why involving another variable to count while you already have _n_?*/&lt;BR /&gt;run;</description>
      <pubDate>Mon, 23 Nov 2015 19:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236073#M14708</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-11-23T19:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Last three rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236074#M14709</link>
      <description>&lt;P&gt;Perhaps even simpler:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have (obs=3);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 19:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Last-three-rows/m-p/236074#M14709</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-11-23T19:30:54Z</dc:date>
    </item>
  </channel>
</rss>

