<?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: End=last option in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690774#M210169</link>
    <description>&lt;P&gt;To read a file in reverse, or enable quick random access, you have to load the allocation chain into memory and use it as a linked list; basically, what a hash iterator does.&lt;/P&gt;
&lt;P&gt;With Windows, you read the chain from the allocation table, in UNIX, fro the inode table.&lt;/P&gt;</description>
    <pubDate>Sun, 11 Oct 2020 10:01:56 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-10-11T10:01:56Z</dc:date>
    <item>
      <title>End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690650#M210107</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.class end=last;
if _n_= last then output;
put last=;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want last observation as per the above code&amp;nbsp;&lt;/P&gt;&lt;P&gt;william&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 07:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690650#M210107</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-10-10T07:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690651#M210108</link>
      <description>&lt;P&gt;See the example &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p00hxg3x8lwivcn1f0e9axziw57y.htm&amp;amp;locale=en#n1pk728cf9t3u6n1lnl1myns8vil" target="_blank" rel="noopener"&gt;in the documendation&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 07:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690651#M210108</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-10T07:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690656#M210110</link>
      <description>&lt;P&gt;Two things:&lt;/P&gt;
&lt;P&gt;1) `end=` allows only two values: 0 when &lt;EM&gt;not in the last&lt;/EM&gt; observation and 1 when &lt;EM&gt;in the las&lt;/EM&gt;t observation so use it like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;data _null_;
set sashelp.class end=last;
if 1 = last then output;
put last=;
run;&lt;/LI-CODE&gt;
&lt;P&gt;2) Remember thai `_N_` is just an "information keeping variable" not the actual number of main loop iteration, so using it in such code is not always good idea, look at this example:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;data _null_;
set sashelp.class end=last;
_N_ = 42;
if _n_= last then output;
put _N_= last=;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 10:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690656#M210110</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-10-10T10:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690662#M210114</link>
      <description>i tried with below code&lt;BR /&gt;only i want get last observation&lt;BR /&gt;data _null_;&lt;BR /&gt;set sashelp.class end=last;&lt;BR /&gt;if 1=last then do ;&lt;BR /&gt;put name=; end;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Sat, 10 Oct 2020 11:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690662#M210114</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-10-10T11:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690663#M210115</link>
      <description>&lt;P&gt;The first block of code from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt; should work perfectly. You made changes and so it doesn't do what you want.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 11:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690663#M210115</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-10T11:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690665#M210117</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Others have shown you how to properly use the dummy variable LAST to test whether the record in hand is the last one in the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your initial concept was to test the condition "_N_=last".&amp;nbsp; &amp;nbsp;You could use _N_ in your test with another argument of the SET statement (the "nobs" argument), as here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set sashelp.class   nobs=nrecs;
  if _n_= nrecs then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But one downside of this approach, and also in the "if last=1" approach is that you have to read the entire dataset to get to the last one - trivial for sashelp.class, but expensive for a billion observations read sequentially.&amp;nbsp; Instead you can do a direct read of the last observation as below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.class nobs=nrecs point=nrecs;
  put name=;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This skips to the last record of the dataset with the very first iteration of the data step by using the POINT= option for direct (as opposed to sequential) access.&amp;nbsp; The only thing to be aware of is the fact that the data step would not automatically stop - because the SET statement would never attempt to read beyond the end of sashelp.class.&amp;nbsp; So, as you can see, I have programmed a STOP statement.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 12:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690665#M210117</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-10-10T12:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690670#M210122</link>
      <description>&lt;P&gt;I like the&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;approach, and would use his point= suggestion if I were programming this myself.&amp;nbsp; However, I find that sometimes it's easier to understand an approach that is similar to what you have already programmed.&amp;nbsp; If were look at that, the changes needed would be simple:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.class end=last;
if _n_= last then output;
put last=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We can just remove a few words here and there to come up with a data set holding just the last observation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data last_observation_only;
set sashelp.class end=last;
if last;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it better suits what you are trying to do, you can use _NULL_ as the data set name and add a PUT statement just before the RUN statement.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 13:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690670#M210122</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-10-10T13:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690674#M210124</link>
      <description>&lt;P&gt;The END= option specifies the name of an automatic flag variable that will contain the state of the most recent read performed by the SET statement.&amp;nbsp; A flag variable is numeric and has value 0 meaning false and 1 meaning true. Automatic variables are part of the program data vector (PDV) but tacitly dropped from the output data set.&amp;nbsp;&amp;nbsp;The state communicated by the variable is the concept 'no more records after this one' or 'that was the last record'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;* Read each record and output the last one;&lt;BR /&gt;data want;
  set have end=last;
  if last;            * subsetting if;
                      * implicit output;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 14:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690674#M210124</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-10-10T14:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690677#M210126</link>
      <description>&lt;P&gt;Mark (&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like your "point=" and totally agree with the approach. It's definitely way more efficient than my proposition with 1=end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have one "side note" idea. It would be nice to have the ability to read datasets backward with something like&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set  sashelp.class(backward=yes)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;don't you think?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 14:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690677#M210126</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-10-10T14:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690751#M210154</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;wrote:&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;I like your "point=" and totally agree with the approach. It's definitely way more efficient than my proposition with 1=end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have one "side note" idea. It would be nice to have the ability to read datasets backward with something like&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set  sashelp.class(backward=yes)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;don't you think?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, but I wonder whether disk file storage systems support efficient performance of reading files backwards. I think there would have to be either&lt;/P&gt;
&lt;P&gt;&amp;nbsp; (1) a list of every disk block address in data record order, presumably easily reversed, or&amp;nbsp;&lt;BR /&gt;&amp;nbsp; (2) backward links from each block to the previous block.&lt;/P&gt;
&lt;P&gt;I am pretty ignorant of disk files systems, so I don 't know the answer to my question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I do know that this could never have been implemented in early usage of SAS, when data sets were as often read from magnetic tape as from disks.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 03:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690751#M210154</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-10-11T03:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: End=last option</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690774#M210169</link>
      <description>&lt;P&gt;To read a file in reverse, or enable quick random access, you have to load the allocation chain into memory and use it as a linked list; basically, what a hash iterator does.&lt;/P&gt;
&lt;P&gt;With Windows, you read the chain from the allocation table, in UNIX, fro the inode table.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 10:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-last-option/m-p/690774#M210169</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-11T10:01:56Z</dc:date>
    </item>
  </channel>
</rss>

