<?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 select last n rows of input records using SQL? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91045#M25975</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about something undocumented:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table post_this as&lt;/P&gt;&lt;P&gt;select &lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;select bank_number, current_date, account_number, balance&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; from dups having max(monotonic())-4 &amp;lt;= monotonic()&amp;lt;= max(monotonic());&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Aug 2012 18:26:15 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2012-08-11T18:26:15Z</dc:date>
    <item>
      <title>How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91042#M25972</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Apologize if multiple postings occured......&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Hi Colleagues, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Could you please help me to select last 5 rows of input records using SQL?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;I used “INOBS=” statement but it selects first five rows.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;sql (inobs=5)&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;create&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; post_this&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;as&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; bank_number&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: 0.5in; padding-left: 90px;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;current_date&amp;nbsp;&amp;nbsp;&amp;nbsp; , &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: 0.5in; padding-left: 90px;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;account_number&amp;nbsp; ,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: 0.5in; padding-left: 90px;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;balance&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; dups&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2012 13:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91042#M25972</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-08-11T13:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91043#M25973</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... one way ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;select nobs into :nobs from dictionary.tables where libname eq 'WORK' and memname eq 'DUPS';&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;create table post_this as &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;select bank_number, current_date, account_number, balance&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;from dups (firstobs=%eval(&amp;amp;nobs-4) obs=&amp;amp;nobs);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2012 14:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91043#M25973</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2012-08-11T14:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91044#M25974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mike's proposal, simplified a bit :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc sql noprint;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;select max(1, nobs-4) into :firstobs from dictionary.tables where libname eq 'WORK' and memname eq 'DUPS';&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;create table post_this as &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;select bank_number, current_date, account_number, balance&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;from dups (firstobs=&amp;amp;firstobs);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;reset print;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;select * from post_this;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2012 18:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91044#M25974</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-08-11T18:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91045#M25975</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about something undocumented:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table post_this as&lt;/P&gt;&lt;P&gt;select &lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;select bank_number, current_date, account_number, balance&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; from dups having max(monotonic())-4 &amp;lt;= monotonic()&amp;lt;= max(monotonic());&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2012 18:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91045#M25975</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-08-11T18:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91046#M25976</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... yes I agree, it's overkill using "OBS=the last observation number" since that's the default behavior (that was a "DUH" moment)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2012 18:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91046#M25976</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2012-08-11T18:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91047#M25977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757;"&gt;Hi &lt;A _jive_internal="true" href="https://communities.sas.com/people/MikeZdeb"&gt;&lt;SPAN style="color: #0e66ba;"&gt;MikeZdeb&lt;/SPAN&gt;&lt;/A&gt;, &lt;A _jive_internal="true" href="https://communities.sas.com/people/PGStats"&gt;&lt;SPAN style="color: #0e66ba;"&gt;PGStats&lt;/SPAN&gt;&lt;/A&gt; and &lt;A _jive_internal="true" href="https://communities.sas.com/people/Hai.kuo"&gt;&lt;SPAN style="color: #0e66ba;"&gt;Hai.kuo&lt;/SPAN&gt;&lt;/A&gt;,&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757;"&gt;&lt;/SPAN&gt;&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757;"&gt;Thank every one of you. &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757;"&gt;All 3 codes are nicely working for my large dataset. (Just deleted one “select” of Hai).&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757;"&gt; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757;"&gt;Every time I get many new things to learn in each code. SAS seems such a massive area.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757;"&gt;Thanks again!&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757;"&gt; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757;"&gt;Mirisage&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;EM&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; text-decoration: underline;"&gt;P.S. There is no way to "click" "correct answer" button for more than one response&lt;/SPAN&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2012 19:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91047#M25977</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-08-11T19:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91048#M25978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;PG's proposal, simplified a bit &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select ((count(*)-4)) into :cnt from &lt;STRONG style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;dups &lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;create table post_this as&lt;/P&gt;&lt;P&gt;select*&lt;/P&gt;&lt;P&gt;from &lt;STRONG style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;dups &lt;/STRONG&gt; (firstobs=&amp;amp;cnt);&lt;/P&gt;&lt;P&gt;reset print;&lt;/P&gt;&lt;P&gt;select * from post_this;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sanjeev.K&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 10:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91048#M25978</guid>
      <dc:creator>kuridisanjeev</dc:creator>
      <dc:date>2012-08-13T10:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91049#M25979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Little bit confusing but great skills..liked it...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sanjeev.K&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 10:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91049#M25979</guid>
      <dc:creator>kuridisanjeev</dc:creator>
      <dc:date>2012-08-13T10:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91050#M25980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,Sanjeev.K&lt;/P&gt;&lt;P&gt;Your code is simpler by its looks, but NOT in practice. PG's code is more efficient since only metadata is involved. Picture if you have million records in 'dups', and how long it would take for 'count(*)' to process?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UPdate:&lt;/P&gt;&lt;P&gt;If you really want to get the obs count directly from 'dups', there is a better way, not a single record will need to be read by doing so.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call symputx('cnt',nobs);stop;&lt;/P&gt;&lt;P&gt;set have nobs=nobs;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 11:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91050#M25980</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-08-13T11:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91051#M25981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Hai.Ku..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hmm yes i do agree with you on this.Actually i am&amp;nbsp; thinking about the simplifying&amp;nbsp; code and not considering about huge data..&lt;/P&gt;&lt;P&gt;Thank you for correcting me ..and one more clarification i need on&amp;nbsp; &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;PG's &lt;/SPAN&gt;code..&lt;/P&gt;&lt;P&gt;Is there any reason for using MAX function??Instead&amp;nbsp; of MAX function we can simply use like&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif; background-color: #ffffff;"&gt;select (nobs-4) into :firstobs &lt;/STRONG&gt;right???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sanjeev.K&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 11:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91051#M25981</guid>
      <dc:creator>kuridisanjeev</dc:creator>
      <dc:date>2012-08-13T11:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91052#M25982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;what if your data set containing 4 or less obs? then&amp;nbsp; (firstobs=&amp;amp;cnt) will cause error. PG's code is to have that covered.&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 12:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91052#M25982</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-08-13T12:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to select last n rows of input records using SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91053#M25983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HaiKuo,&lt;/P&gt;&lt;P&gt;One of advantages of Sanjeev.K's code is he can pick up the real nobs of a dataset. whereas, metadata nobs from dictionary table is not real nobs . For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data class;set sashelp.class;run;&lt;/P&gt;&lt;P&gt;data class;&lt;/P&gt;&lt;P&gt;modify class;&lt;/P&gt;&lt;P&gt;if sex&amp;nbsp; eq 'M'&amp;nbsp; then remove;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select nobs from dictionary.tables where libname='WORK' and memname='CLASS';&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it is still 19.&lt;/P&gt;&lt;P&gt;But we can use nlobs instead of nobs to rectify this problem.&lt;/P&gt;&lt;P&gt;select nlobs from dictionary.tables where libname='WORK' and memname='CLASS';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Aug 2012 03:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-last-n-rows-of-input-records-using-SQL/m-p/91053#M25983</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-08-14T03:12:29Z</dc:date>
    </item>
  </channel>
</rss>

