<?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 statement sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/End-data-step-option-usage/m-p/695377#M212188</link>
    <description>&lt;P&gt;Are you competing for ugliest and least maintainable code? If yes, you're not quite there, but you deserve an honorable mention. Please look at the many examples of well-formatted code posted by the senior members here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tips3; 
set mean_premium;
set ia.region_west end=last; /* you define a variable that will be set to 1 when the last observation is read, but you never use it */

proc print; /* the proc statement constitutes a step boundary, so the data step ends here */
var region premium mean_premium;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since you use two SET statements, it may also be that the last observation of ia.region_west is never read (if mean_premium has less observations).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The END= you used is not a&amp;nbsp;&lt;EM&gt;statement&lt;/EM&gt; in itself, but an&amp;nbsp;&lt;EM&gt;option&lt;/EM&gt; of the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/351456"&gt;@Curious4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;how do i reference the last observation with the end statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data region_west;
set ia.region_west end=last;
keep idnum region jcode premium company plan;





proc means noprint data=region_west;
var premium;
output out=mean_premium mean=mean_premium;
data tips2;
/*add menas when n=1*/
if _N_=1 then set mean_premium;

set ia.region_west end=last;
proc print;
	var region premium mean_premium;
run;


data tips3; set mean_premium;
set ia.region_west end=last;
proc print; 
	var region premium mean_premium;
run;&lt;/PRE&gt;
&lt;P&gt;I tried to put the end statement in my set statement but didn't work.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Oct 2020 22:38:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-10-29T22:38:06Z</dc:date>
    <item>
      <title>End - data step option usage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-data-step-option-usage/m-p/695373#M212186</link>
      <description>&lt;P&gt;how do i reference the last observation with the end statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data region_west;
set ia.region_west end=last;
keep idnum region jcode premium company plan;





proc means noprint data=region_west;
var premium;
output out=mean_premium mean=mean_premium;
data tips2;
/*add menas when n=1*/
if _N_=1 then set mean_premium;

set ia.region_west end=last;
proc print;
	var region premium mean_premium;
run;


data tips3; set mean_premium;
set ia.region_west end=last;
proc print; 
	var region premium mean_premium;
run;&lt;/PRE&gt;
&lt;P&gt;I tried to put the end statement in my set statement but didn't work.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 23:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-data-step-option-usage/m-p/695373#M212186</guid>
      <dc:creator>Curious4</dc:creator>
      <dc:date>2020-10-29T23:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: end statement sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-data-step-option-usage/m-p/695377#M212188</link>
      <description>&lt;P&gt;Are you competing for ugliest and least maintainable code? If yes, you're not quite there, but you deserve an honorable mention. Please look at the many examples of well-formatted code posted by the senior members here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tips3; 
set mean_premium;
set ia.region_west end=last; /* you define a variable that will be set to 1 when the last observation is read, but you never use it */

proc print; /* the proc statement constitutes a step boundary, so the data step ends here */
var region premium mean_premium;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since you use two SET statements, it may also be that the last observation of ia.region_west is never read (if mean_premium has less observations).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The END= you used is not a&amp;nbsp;&lt;EM&gt;statement&lt;/EM&gt; in itself, but an&amp;nbsp;&lt;EM&gt;option&lt;/EM&gt; of the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/351456"&gt;@Curious4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;how do i reference the last observation with the end statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data region_west;
set ia.region_west end=last;
keep idnum region jcode premium company plan;





proc means noprint data=region_west;
var premium;
output out=mean_premium mean=mean_premium;
data tips2;
/*add menas when n=1*/
if _N_=1 then set mean_premium;

set ia.region_west end=last;
proc print;
	var region premium mean_premium;
run;


data tips3; set mean_premium;
set ia.region_west end=last;
proc print; 
	var region premium mean_premium;
run;&lt;/PRE&gt;
&lt;P&gt;I tried to put the end statement in my set statement but didn't work.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 22:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-data-step-option-usage/m-p/695377#M212188</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-29T22:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: End - data step option usage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-data-step-option-usage/m-p/695382#M212192</link>
      <description>FYI - I modified your subject line to better reflect your topic. You're referring to the data step option, not the END statement which has a very different functionality. Yes, it can be confusing when formats, functions, call routines, statements and options all have the same names.</description>
      <pubDate>Thu, 29 Oct 2020 23:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-data-step-option-usage/m-p/695382#M212192</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-29T23:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: End - data step option usage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/End-data-step-option-usage/m-p/695383#M212193</link>
      <description>&lt;PRE&gt;data region_west;
set ia.region_west end=last;
keep idnum region jcode premium company plan;


if last then do;
     *add in what ever you want done on last step;&lt;BR /&gt;put "This is the last record!!!!!!!!!!!!" _n_;
end;


run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can conditionally check if you're on the last record and then execute a command as needed. The example above illustrates this, you should be able to check the log and see the statement in the log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/351456"&gt;@Curious4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;how do i reference the last observation with the end statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data region_west;
set ia.region_west end=last;
keep idnum region jcode premium company plan;





proc means noprint data=region_west;
var premium;
output out=mean_premium mean=mean_premium;
data tips2;
/*add menas when n=1*/
if _N_=1 then set mean_premium;

set ia.region_west end=last;
proc print;
	var region premium mean_premium;
run;


data tips3; set mean_premium;
set ia.region_west end=last;
proc print; 
	var region premium mean_premium;
run;&lt;/PRE&gt;
&lt;P&gt;I tried to put the end statement in my set statement but didn't work.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 23:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/End-data-step-option-usage/m-p/695383#M212193</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-29T23:18:04Z</dc:date>
    </item>
  </channel>
</rss>

