<?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: What is the purpose of end=eof? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565151#M158626</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63520"&gt;@imdickson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a comment as a supplement to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;'s good explanation.&amp;nbsp;You will get a lot of hits in google, if you search for&amp;nbsp; "sas end = dataset option" instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SAS END= dataset option can take any valid SAS variable name as argument. The use of "eof" (end-of-file) as variable name is a tradition from way back, but not part of the syntax, so this works the same way;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
	do i = 1 to 10; output;
end;
data b; set a end=last_observation;
	if last_observation then put i=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a data step has more than one Set statement, it is often useful to have a check for last observation in each statement, which requires different variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jun 2019 08:43:59 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2019-06-11T08:43:59Z</dc:date>
    <item>
      <title>What is the purpose of end=eof?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565139#M158617</link>
      <description>&lt;P&gt;Hi everyone. Recently i was asked by apprentice about SAS function end=eof and to my shocking, i know nothing about this.&lt;/P&gt;&lt;P&gt;Upon Google search, i only managed to find 1 PDF file about end of file but i still dont understand the purpose of it.&lt;/P&gt;&lt;P&gt;The link is :&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings09/074-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/074-2009.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have a better explanation or elaboration of end=eof ? I have never used that in my life.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 08:13:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565139#M158617</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2019-06-11T08:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: What is the purpose of end=eof?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565144#M158621</link>
      <description>&lt;P&gt;You can specify end=eof in the set statement. &lt;STRONG&gt;Eof&amp;nbsp;&lt;/STRONG&gt;will then be a binary variable (0/1) with the value 1 for the last observation in the data set and 0 otherwise.&amp;nbsp;&lt;STRONG&gt;Eof &lt;/STRONG&gt;is automatically dropped. However, for demonstrational purposes, I assign the value to another variable &lt;STRONG&gt;var&amp;nbsp;&lt;/STRONG&gt;below.&amp;nbsp;See the example below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    set sashelp.class end=eof;
    var=eof;
run;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This enabled you to eg. keep only the last observation in a data set like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
    set sashelp.class end=eof;
    if eof=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jun 2019 08:21:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565144#M158621</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-11T08:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: What is the purpose of end=eof?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565149#M158624</link>
      <description>&lt;P&gt;Thanks for the clear explanation and sample.&lt;/P&gt;&lt;P&gt;To my understanding, this would be the only purpose of using end=eof right?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 08:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565149#M158624</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2019-06-11T08:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: What is the purpose of end=eof?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565150#M158625</link>
      <description>&lt;P&gt;No. But it is a classic use of the end= Option &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes users want to keep all observation &lt;EM&gt;except&lt;/EM&gt; the last one. Also a nice use for the End= Option.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 08:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565150#M158625</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-11T08:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: What is the purpose of end=eof?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565151#M158626</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63520"&gt;@imdickson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a comment as a supplement to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;'s good explanation.&amp;nbsp;You will get a lot of hits in google, if you search for&amp;nbsp; "sas end = dataset option" instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SAS END= dataset option can take any valid SAS variable name as argument. The use of "eof" (end-of-file) as variable name is a tradition from way back, but not part of the syntax, so this works the same way;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
	do i = 1 to 10; output;
end;
data b; set a end=last_observation;
	if last_observation then put i=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a data step has more than one Set statement, it is often useful to have a check for last observation in each statement, which requires different variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 08:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565151#M158626</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-06-11T08:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: What is the purpose of end=eof?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565157#M158630</link>
      <description>&lt;P&gt;There are multiple uses for this. Imagine you need to write a csv where the last line is expected to hold the number of records only:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
file "myoutfile.csv" dlm=',' dsd;
set sashelp.class end=eof;
retain recordcount 0;
if _n_ = 1 then put 'name,sex,age,height,weight';
put name sex age height weight;
recordcount + 1;
if eof then put recordcount;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jun 2019 09:33:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565157#M158630</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-11T09:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: What is the purpose of end=eof?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565290#M158691</link>
      <description>&lt;P&gt;Please not that I do not recommend using that particular combination: end=eof&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because &lt;STRONG&gt;eof&lt;/STRONG&gt; is also an option for a set statement which&lt;/P&gt;
&lt;P&gt;As is &lt;STRONG&gt;eov&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 15:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/565290#M158691</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-11T15:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: What is the purpose of end=eof?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/594947#M171071</link>
      <description>Is there an equivalent "start" option to get the first row/start of file?</description>
      <pubDate>Wed, 09 Oct 2019 06:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/594947#M171071</guid>
      <dc:creator>sustagens</dc:creator>
      <dc:date>2019-10-09T06:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: What is the purpose of end=eof?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/594949#M171073</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281550"&gt;@sustagens&lt;/a&gt;&amp;nbsp;please start a new thread for this question. That way, we keep different subjects apart and help future users. Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 06:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/594949#M171073</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-09T06:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: What is the purpose of end=eof?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/594951#M171075</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63520"&gt;@imdickson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the clear explanation and sample.&lt;/P&gt;
&lt;P&gt;To my understanding, this would be the only purpose of using end=eof right?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There are quite a few use cases for the end= dataset option. You use it whenever something needs to happen when reading the last observation from table(s). Below another common use case.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  do while(not eof);
    set sashelp.class end=eof;
    output;
  end;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Oct 2019 06:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/m-p/594951#M171075</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-10-09T06:18:58Z</dc:date>
    </item>
  </channel>
</rss>

