<?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: getting last observation from a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11403#M1046</link>
    <description>This would be the syntax, however it will not work when data is read from datalines. It will work when reading from a file, and if you put it on a set statement for a dataset:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data ex;&lt;BR /&gt;
infile datalines END=LAST;&lt;BR /&gt;
input a;&lt;BR /&gt;
IF LAST;&lt;BR /&gt;
datalines;&lt;BR /&gt;
66 &lt;BR /&gt;
77&lt;BR /&gt;
88&lt;BR /&gt;
;</description>
    <pubDate>Thu, 26 Mar 2009 09:46:06 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-03-26T09:46:06Z</dc:date>
    <item>
      <title>getting last observation from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11402#M1045</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
is there any option to get last observation in a dataset( using firstobs , obs dataset options)&lt;BR /&gt;
&lt;BR /&gt;
ex:&lt;BR /&gt;
data ex;&lt;BR /&gt;
input a;&lt;BR /&gt;
datalines;&lt;BR /&gt;
66 &lt;BR /&gt;
77&lt;BR /&gt;
88&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
output:&lt;BR /&gt;
88</description>
      <pubDate>Thu, 26 Mar 2009 09:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11402#M1045</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-26T09:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: getting last observation from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11403#M1046</link>
      <description>This would be the syntax, however it will not work when data is read from datalines. It will work when reading from a file, and if you put it on a set statement for a dataset:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data ex;&lt;BR /&gt;
infile datalines END=LAST;&lt;BR /&gt;
input a;&lt;BR /&gt;
IF LAST;&lt;BR /&gt;
datalines;&lt;BR /&gt;
66 &lt;BR /&gt;
77&lt;BR /&gt;
88&lt;BR /&gt;
;</description>
      <pubDate>Thu, 26 Mar 2009 09:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11403#M1046</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-26T09:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: getting last observation from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11404#M1047</link>
      <description>thank u very much.&lt;BR /&gt;
&lt;BR /&gt;
is there any possibility using with  firstobs, obs dataset options for creating that dataset.</description>
      <pubDate>Thu, 26 Mar 2009 11:32:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11404#M1047</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-26T11:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: getting last observation from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11405#M1048</link>
      <description>In SAS 9.1.3, the SET stmt FIRSTOBS=MAX parameter generates an error, unfortunately, for what appears to be an incorrect "last observation" calculation (based on the error message).&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data x;&lt;BR /&gt;
do i=1 to 21;&lt;BR /&gt;
  output;&lt;BR /&gt;
end;&lt;BR /&gt;
stop;&lt;BR /&gt;
run;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
set x (firstobs=max);&lt;BR /&gt;
putlog _all_;&lt;BR /&gt;
stop;&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 26 Mar 2009 13:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11405#M1048</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-26T13:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: getting last observation from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11406#M1049</link>
      <description>Hi SaiRam,&lt;BR /&gt;
&lt;BR /&gt;
If u know the number of Observations(firstobs or obs).&lt;BR /&gt;
&lt;BR /&gt;
Try this.,&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
infile cards&lt;BR /&gt;
firstobs=3;&lt;BR /&gt;
input a;&lt;BR /&gt;
cards;&lt;BR /&gt;
76&lt;BR /&gt;
56&lt;BR /&gt;
98&lt;BR /&gt;
;&lt;BR /&gt;
proc print;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Venky.</description>
      <pubDate>Fri, 27 Mar 2009 12:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11406#M1049</guid>
      <dc:creator>venkatesh</dc:creator>
      <dc:date>2009-03-27T12:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: getting last observation from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11407#M1050</link>
      <description>Sairam,&lt;BR /&gt;
&lt;BR /&gt;
The following utility macro might solve your problem:&lt;BR /&gt;
&lt;BR /&gt;
%MACRO obs(lib=,mem=);                    &lt;BR /&gt;
 %LET ds    = %SYSFUNC(OPEN(&amp;amp;lib..&amp;amp;mem)); &lt;BR /&gt;
 %LET noobs = %SYSFUNC(ATTRN(&amp;amp;ds,NOBS));  &lt;BR /&gt;
 %LET ds    = %SYSFUNC(CLOSE(&amp;amp;ds));       &lt;BR /&gt;
 &amp;amp;noobs;                                  &lt;BR /&gt;
%MEND  obs;                               &lt;BR /&gt;
&lt;BR /&gt;
If we generate the following dataset - a1&lt;BR /&gt;
&lt;BR /&gt;
data a1;&lt;BR /&gt;
  do val = 1 to 100;&lt;BR /&gt;
   output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Use the macro statement - %LET to assign a macro variable (obs_in_dset in this example) the output of the %obs macro. In the macro call name the sas library in which your dataset resides (lib=work) and the sas dataset name (mem=a1)&lt;BR /&gt;
&lt;BR /&gt;
e.g.&lt;BR /&gt;
%let obs_in_dset = %obs(lib=work,mem=a1);&lt;BR /&gt;
&lt;BR /&gt;
Now when you want to read the last obs in the a1 dataset use&lt;BR /&gt;
&lt;BR /&gt;
data lastina1;&lt;BR /&gt;
 set a1(firstobs=&amp;amp;obs_in_dset);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I hope you find this useful.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
BPD</description>
      <pubDate>Fri, 27 Mar 2009 12:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11407#M1050</guid>
      <dc:creator>BPD</dc:creator>
      <dc:date>2009-03-27T12:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: getting last observation from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11408#M1051</link>
      <description>when your data are in a SAS data set, you can point read the last row (without reading the other rows):[pre]   data last_row ;&lt;BR /&gt;
      set  your_dataset nobs=nobs point= nobs;&lt;BR /&gt;
      output ;&lt;BR /&gt;
      stop ;&lt;BR /&gt;
   run ;[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
was that what was wanted?&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Sat, 28 Mar 2009 18:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/11408#M1051</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-28T18:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: getting last observation from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/260852#M50665</link>
      <description>_Exactly_ what I needed. Thanks PeterC wherever you are.</description>
      <pubDate>Fri, 01 Apr 2016 22:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-last-observation-from-a-dataset/m-p/260852#M50665</guid>
      <dc:creator>bentleyj1</dc:creator>
      <dc:date>2016-04-01T22:45:24Z</dc:date>
    </item>
  </channel>
</rss>

