<?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: How to do ouput last observation of a SAS data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/262044#M51084</link>
    <description>&lt;P&gt;Ever any new questions? Well I asked this one back in 2004...&lt;/P&gt;
&lt;P&gt;&lt;A href="http://marc.info/?l=sas-l&amp;amp;m=1166250948107016&amp;amp;w=2" target="_blank"&gt;http://marc.info/?l=sas-l&amp;amp;m=1166250948107016&amp;amp;w=2&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Apr 2016 11:54:24 GMT</pubDate>
    <dc:creator>bpowell</dc:creator>
    <dc:date>2016-04-07T11:54:24Z</dc:date>
    <item>
      <title>How to output last observation of a SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8404#M304</link>
      <description>&lt;P&gt;AS known to us, _n_ can be used in IF-Then statement for manipulation for any speciifed observation when the observation number is known. How to do the same thing for last observation since we do not know it's obervation number&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 14:43:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8404#M304</guid>
      <dc:creator>Steve_Shanghai</dc:creator>
      <dc:date>2016-07-19T14:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8405#M305</link>
      <description>Check out the END= option on the SET statement.  I think that will do what you want.</description>
      <pubDate>Tue, 07 Jun 2011 02:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8405#M305</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2011-06-07T02:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8406#M306</link>
      <description>data test;&lt;BR /&gt;
  set sashelp.class end=eof;&lt;BR /&gt;
  if eof then output;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 07 Jun 2011 08:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8406#M306</guid>
      <dc:creator>RMP</dc:creator>
      <dc:date>2011-06-07T08:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8407#M307</link>
      <description>I get it, Thanks alot!</description>
      <pubDate>Tue, 07 Jun 2011 08:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8407#M307</guid>
      <dc:creator>Steve_Shanghai</dc:creator>
      <dc:date>2011-06-07T08:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8408#M308</link>
      <description>If the purpose of the exercise is to access the last obs "only" then a more direct approach can be used.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data class;&lt;BR /&gt;
   set sashelp.class;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
data class;&lt;BR /&gt;
   modify class end=eof;&lt;BR /&gt;
   *remove;&lt;BR /&gt;
   if eof or ranuni(12344) lt .2 then remove;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run; &lt;BR /&gt;
data last;&lt;BR /&gt;
   if eof then stop;&lt;BR /&gt;
   do _n_ = nobs to 1 by -1 until(_error_ eq 0);&lt;BR /&gt;
      _error_ = 0;&lt;BR /&gt;
      set class point=_n_ nobs=nobs;&lt;BR /&gt;
      _obs_ = _n_;&lt;BR /&gt;
      end;&lt;BR /&gt;
   if _error_ eq 0 then output;&lt;BR /&gt;
   stop;&lt;BR /&gt;
   set class(drop=_all_) end=eof;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]

Added code to check for data sets with zero obs.&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: data _null_;</description>
      <pubDate>Tue, 07 Jun 2011 11:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8408#M308</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-06-07T11:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to output last observation of a SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8409#M309</link>
      <description>&lt;P&gt;&lt;EM&gt;Editor's note: this is a&amp;nbsp;&lt;STRONG&gt;very&lt;/STRONG&gt; popular question. &amp;nbsp;To help others to find the answer, we have consolidated the most helpful answers into this one reply as an Accepted Solution. &amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or ...&lt;BR /&gt; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Simple approach */
data last;
    /* get number of records (N) */
    if 0 then
        set sashelp.class nobs=nobs end=eof;
    /* use POINT= to get nth record */
    set sashelp.class point=nobs;
    output;
    stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;More robust approach from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__﻿&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create sample data */
data class;
    set sashelp.class;
run;
data class;
    modify class end=eof;
    /* uncomment this to create empty set for test */
    *remove;
    if eof or ranuni(12344) lt .2 then
        remove;
run;
/* print all records */
proc print;
run;

/* find last record, handle empty sets */
data last;
    if eof then
        stop;
    do _n_ = nobs to 1 by -1 until(_error_ eq 0);
        _error_ = 0;
        set class point=_n_ nobs=nobs;
        _obs_ = _n_;
    end;
    if _error_ eq 0 then
        output;
    stop;
    set class(drop=_all_) end=eof;
run;

/* print last record */
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jul 2016 14:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8409#M309</guid>
      <dc:creator>RMP</dc:creator>
      <dc:date>2016-07-19T14:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8410#M310</link>
      <description>&amp;gt; or ...&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data test;&lt;BR /&gt;
&amp;gt;   if 0 then set sashelp.class nobs=nobs end=eof;&lt;BR /&gt;
&amp;gt; set sashelp.class point=nobs;&lt;BR /&gt;
&amp;gt;   output;&lt;BR /&gt;
&amp;gt; stop;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&lt;BR /&gt;
No, because if the last observation was REMOVEd as in my example, your program won't work.</description>
      <pubDate>Tue, 07 Jun 2011 13:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8410#M310</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-06-07T13:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8411#M311</link>
      <description>Good point. What you lose in readability/maintainability you gain in robustness.</description>
      <pubDate>Tue, 07 Jun 2011 13:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8411#M311</guid>
      <dc:creator>RMP</dc:creator>
      <dc:date>2011-06-07T13:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8412#M312</link>
      <description>have we seen this topic before?</description>
      <pubDate>Wed, 08 Jun 2011 05:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8412#M312</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-06-08T05:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8413#M313</link>
      <description>Do you mean how to find the last obs or the readability/maintainability of simple data steps?</description>
      <pubDate>Wed, 08 Jun 2011 12:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8413#M313</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-06-08T12:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8414#M314</link>
      <description>just the last obs. I'm sure I've read your code before.</description>
      <pubDate>Wed, 08 Jun 2011 19:24:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8414#M314</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-06-08T19:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8415#M315</link>
      <description>Peter,&lt;BR /&gt;
&lt;BR /&gt;
How many questions are "really" new?&lt;BR /&gt;
&lt;BR /&gt;
Art&lt;BR /&gt;
&amp;gt; just the last obs. I'm sure I've read your code&lt;BR /&gt;
&amp;gt; before.</description>
      <pubDate>Thu, 09 Jun 2011 23:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/8415#M315</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-06-09T23:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to do ouput last observation of a SAS data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/262044#M51084</link>
      <description>&lt;P&gt;Ever any new questions? Well I asked this one back in 2004...&lt;/P&gt;
&lt;P&gt;&lt;A href="http://marc.info/?l=sas-l&amp;amp;m=1166250948107016&amp;amp;w=2" target="_blank"&gt;http://marc.info/?l=sas-l&amp;amp;m=1166250948107016&amp;amp;w=2&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 11:54:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/m-p/262044#M51084</guid>
      <dc:creator>bpowell</dc:creator>
      <dc:date>2016-04-07T11:54:24Z</dc:date>
    </item>
  </channel>
</rss>

