<?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 n distinct obs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42975#M8798</link>
    <description>If the table is too large to process (sort, dedup, summarise) as suggested above,&lt;BR /&gt;
you can read it starting from the end:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data t; &lt;BR /&gt;
  if 0 then set SASHELP.CLASS nobs=NOBS;&lt;BR /&gt;
  do I= NOBS to 1 by -1;&lt;BR /&gt;
    set SASHELP.CLASS point=I;&lt;BR /&gt;
    put AGE=;&lt;BR /&gt;
  end;&lt;BR /&gt;
  stop;&lt;BR /&gt;
run;[/pre]&lt;BR /&gt;
You can add some logic in the data step to do what you want, like filling up an array with unique values as you go.</description>
    <pubDate>Wed, 10 Jun 2009 23:11:01 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2009-06-10T23:11:01Z</dc:date>
    <item>
      <title>last n distinct obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42971#M8794</link>
      <description>Hi friends,&lt;BR /&gt;
what is most efficient way to find last 10 distinct obs from a data set.&lt;BR /&gt;
&lt;BR /&gt;
we dont have such facility in SAS proc sql&lt;BR /&gt;
like ---&lt;BR /&gt;
select last 10 distinct abc, xyz from tbl where xyz='ijk';&lt;BR /&gt;
&lt;BR /&gt;
Thank you.&lt;BR /&gt;
&lt;BR /&gt;
regards,&lt;BR /&gt;
Avi</description>
      <pubDate>Wed, 10 Jun 2009 08:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42971#M8794</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-10T08:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: last n distinct obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42972#M8795</link>
      <description>Look at following SAS programming opportunity:  &lt;BR /&gt;
&lt;BR /&gt;
1) capture SAS-reserved variable _N_ as OBSNUM for highest location identification.&lt;BR /&gt;
2) use PROC SUMMARY to generate a _FREQ_ count.  Specify ID OBSNUM to get the last occurence.&lt;BR /&gt;
3) use SORT with BY DESCENDING _FREQ_ DESCENDING OBSNUM.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 10 Jun 2009 11:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42972#M8795</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-10T11:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: last n distinct obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42973#M8796</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
To find last n observation from a dataset &lt;BR /&gt;
&lt;BR /&gt;
data temp;&lt;BR /&gt;
set sashelp.class nobs=LASTN;&lt;BR /&gt;
if _n_ &amp;gt; (LASTN-n);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
This will get you the last n obs.&lt;BR /&gt;
&lt;BR /&gt;
If you  want to get distinct obseravtions,&lt;BR /&gt;
Please create a dataset with distinct obseravtion first and apply this logic &lt;BR /&gt;
&lt;BR /&gt;
Hope this will help you.</description>
      <pubDate>Wed, 10 Jun 2009 11:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42973#M8796</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-10T11:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: last n distinct obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42974#M8797</link>
      <description>Hey &lt;BR /&gt;
&lt;BR /&gt;
Thanks for the reply.&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
Avi</description>
      <pubDate>Wed, 10 Jun 2009 12:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42974#M8797</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-10T12:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: last n distinct obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42975#M8798</link>
      <description>If the table is too large to process (sort, dedup, summarise) as suggested above,&lt;BR /&gt;
you can read it starting from the end:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data t; &lt;BR /&gt;
  if 0 then set SASHELP.CLASS nobs=NOBS;&lt;BR /&gt;
  do I= NOBS to 1 by -1;&lt;BR /&gt;
    set SASHELP.CLASS point=I;&lt;BR /&gt;
    put AGE=;&lt;BR /&gt;
  end;&lt;BR /&gt;
  stop;&lt;BR /&gt;
run;[/pre]&lt;BR /&gt;
You can add some logic in the data step to do what you want, like filling up an array with unique values as you go.</description>
      <pubDate>Wed, 10 Jun 2009 23:11:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42975#M8798</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-06-10T23:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: last n distinct obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42976#M8799</link>
      <description>A slight variation on the post from Chris@newzealand.&lt;BR /&gt;
Store the number of obs - 9 into a macro variable.&lt;BR /&gt;
&lt;BR /&gt;
data t;&lt;BR /&gt;
 if 0 then set SASHELP.CLASS nobs=NOBS;&lt;BR /&gt;
 call symput('nobs',nobs-9);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Then read the data from that point in the dataset.&lt;BR /&gt;
data t1;&lt;BR /&gt;
 set SASHELP.CLASS(firstobs=&amp;amp;nobs);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
BPD</description>
      <pubDate>Thu, 11 Jun 2009 07:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42976#M8799</guid>
      <dc:creator>BPD</dc:creator>
      <dc:date>2009-06-11T07:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: last n distinct obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42977#M8800</link>
      <description>Hey , Thanks Chris&lt;BR /&gt;
&lt;BR /&gt;
I have got the required output... &lt;BR /&gt;
Thank you all for your help..&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
Avi</description>
      <pubDate>Thu, 11 Jun 2009 08:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/last-n-distinct-obs/m-p/42977#M8800</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-11T08:26:45Z</dc:date>
    </item>
  </channel>
</rss>

