<?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: multiple table extract last obs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616570#M180510</link>
    <description>&lt;P&gt;You could also use proc SQL, substitute the name of your table in myBigtable.&amp;nbsp; The code should work to get you the last 5 observations of the table.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table 
Last_Five as
  select *
    from myBigTable (firstobs=%eval(%sysfunc(attrn(%sysfunc(open(MyBigTable)),nlobs))-4))
  ;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 10 Jan 2020 18:39:54 GMT</pubDate>
    <dc:creator>jhammouda</dc:creator>
    <dc:date>2020-01-10T18:39:54Z</dc:date>
    <item>
      <title>multiple table extract last obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616552#M180508</link>
      <description>&lt;P&gt;Hi&amp;nbsp; guys&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have three tables in these three tables suppose i do not know how many observations in each table so&lt;/P&gt;&lt;P&gt;i want to find total observations and extract last five observations from each table at a time how can i write code&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 17:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616552#M180508</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-01-10T17:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: multiple table extract last obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616563#M180509</link>
      <description>&lt;P&gt;Retrieve the number of observations (nobs) from dictionary.tables, subtract 4, and use the result in a firstobs= option.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 18:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616563#M180509</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-10T18:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: multiple table extract last obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616570#M180510</link>
      <description>&lt;P&gt;You could also use proc SQL, substitute the name of your table in myBigtable.&amp;nbsp; The code should work to get you the last 5 observations of the table.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table 
Last_Five as
  select *
    from myBigTable (firstobs=%eval(%sysfunc(attrn(%sysfunc(open(MyBigTable)),nlobs))-4))
  ;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jan 2020 18:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616570#M180510</guid>
      <dc:creator>jhammouda</dc:creator>
      <dc:date>2020-01-10T18:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: multiple table extract last obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616578#M180511</link>
      <description>&lt;P&gt;Use the POINT= and NOBS= option.&amp;nbsp; (Note requires that table does not contain deleted observations since POINT= operates on actual observation number and not logical observation number).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do p=max(1,nobs-4) to nobs ;
    set have point=p nobs=nobs;
    output;
  end;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jan 2020 19:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616578#M180511</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-10T19:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: multiple table extract last obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616684#M180566</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
select sum(nobs) as total_obs from dictionary.tables 
where libname = 'WORK' and memtype = 'data';
select memname, nobs from dictionary.tables 
where libname = 'WORK';
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the above code where subtract 4&amp;nbsp;&lt;/P&gt;&lt;P&gt;please explain&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 14:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616684#M180566</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-01-11T14:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: multiple table extract last obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616752#M180616</link>
      <description>That would give you the number of total observations. SAS allows you to access data sets using the FIRSTOBS, so if you take the Sum(nobs), you didn't give it a name, and subtract four that's the first observation you want. &lt;BR /&gt;&lt;BR /&gt;ie &lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set sashelp.class (firstobs = 15);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;I would recommend Tom's solution since it's the simplest and you can generalize it for your multiple tables as needed. Either way, when processing multiple tables you'll need a macro or loop of some kind to get that working correctly.</description>
      <pubDate>Sun, 12 Jan 2020 01:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616752#M180616</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-12T01:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: multiple table extract last obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/708039#M217497</link>
      <description>Thanks for your reply i want last n observations from all datasets in a library how can we do that</description>
      <pubDate>Thu, 24 Dec 2020 04:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/708039#M217497</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-12-24T04:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: multiple table extract last obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/708040#M217498</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks for your reply i want last n observations from all datasets in a library how can we do that&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What do you want to DO with the last N observations from these datasets?&amp;nbsp; Do the datasets all have the exact same structure?&amp;nbsp; If so you might be able to put the results into a single dataset. Otherwise you will need to either make new datasets with jsut the last N observations or just make some type of report.&amp;nbsp; So what it is that you want?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 04:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/708040#M217498</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-24T04:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: multiple table extract last obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/708045#M217501</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro GetLast5(lib,n);
  options dlcreatedir;
  libname out "%sysfunc(pathname(work))\out";
  data _null_;
    set sashelp.vtable(where=(memtype='DATA' and libname=upcase("&amp;amp;lib")));
    call symputx(cats('DS',_n_),memname);
         if nlobs=0   then call symputx(cats('obs',_n_),1);
    else if nlobs=&amp;gt;&amp;amp;n then call symputx(cats('obs',_n_),nlobs-(&amp;amp;n-1));
    else                   call symputx(cats('obs',_n_),nlobs);
    call symputx('nobs',_n_);
  run;

  %do i=1 %to &amp;amp;nobs;
    data out.&amp;amp;&amp;amp;DS&amp;amp;i;
      set &amp;amp;lib..&amp;amp;&amp;amp;DS&amp;amp;i(firstobs=&amp;amp;&amp;amp;obs&amp;amp;i);
    run;
  %end;
%Mend;
&lt;BR /&gt;/* try extract last 5 obs from sashelp library */
%GetLast5(sashelp,5);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Dec 2020 06:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/708045#M217501</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2020-12-24T06:38:56Z</dc:date>
    </item>
  </channel>
</rss>

