<?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: Does the start= option inside of a data step actually exist? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865084#M341607</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  do obs = 1 to 5;
    output;
  end;
run;

data b;
  set a end=eof;
  if _N_ = 1 then firstobs = 1;
  if eof then lastobs = 1;
run;

data c;
  set a (firstobs=2 obs=4) end=eof;
  if _N_ = 1 then firstobs = 1;
  if eof then lastobs = 1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 19 Mar 2023 10:08:39 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2023-03-19T10:08:39Z</dc:date>
    <item>
      <title>Does the start= option inside of a data step actually exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865080#M341605</link>
      <description>&lt;P&gt;Hi, just reading about &lt;STRONG&gt;end=&lt;/STRONG&gt; option in the set statement of data step in &lt;A href="https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/td-p/565139" target="_self"&gt;this thread.&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think the OP of that thread ever made another about the existence of &lt;STRONG&gt;start=&lt;/STRONG&gt; option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I type &lt;STRONG&gt;start= &lt;/STRONG&gt;or&lt;STRONG&gt; being= &lt;/STRONG&gt;in the set statement, there is no pop up with links to doc, so I assume &lt;STRONG&gt;start= &lt;/STRONG&gt;option does not actually exist in the set statement of the data step?&lt;/P&gt;</description>
      <pubDate>Sun, 19 Mar 2023 09:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865080#M341605</guid>
      <dc:creator>Nietzsche</dc:creator>
      <dc:date>2023-03-19T09:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Does the start= option inside of a data step actually exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865082#M341606</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/431484"&gt;@Nietzsche&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, just reading about &lt;STRONG&gt;end=&lt;/STRONG&gt; option in the set statement of data step in &lt;A href="https://communities.sas.com/t5/SAS-Programming/What-is-the-purpose-of-end-eof/td-p/565139" target="_self"&gt;this thread.&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think the OP of that thread ever made another about the existence of &lt;STRONG&gt;start=&lt;/STRONG&gt; option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I type &lt;STRONG&gt;start= &lt;/STRONG&gt;or&lt;STRONG&gt; being= &lt;/STRONG&gt;in the set statement, there is no pop up with links to doc, so I assume &lt;STRONG&gt;start= &lt;/STRONG&gt;option does not actually exist in the set statement of the data step?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What would a START= option do? Would it signal the beginning of a data step (similar to END= signalling the end of a data step)? If that's what you want, you can use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if _n_=1 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Mar 2023 10:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865082#M341606</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-19T10:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Does the start= option inside of a data step actually exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865084#M341607</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  do obs = 1 to 5;
    output;
  end;
run;

data b;
  set a end=eof;
  if _N_ = 1 then firstobs = 1;
  if eof then lastobs = 1;
run;

data c;
  set a (firstobs=2 obs=4) end=eof;
  if _N_ = 1 then firstobs = 1;
  if eof then lastobs = 1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Mar 2023 10:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865084#M341607</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-03-19T10:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Does the start= option inside of a data step actually exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865085#M341608</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/431484"&gt;@Nietzsche&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, my text seems to have dissappeared.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no &lt;STRONG&gt;start=&lt;/STRONG&gt; option. The &lt;STRONG&gt;end=xxx&lt;/STRONG&gt; option sets the value of variable &lt;STRONG&gt;xxx&lt;/STRONG&gt; to 1 (true) when the current observation is the last observation read into the program vector. The automatic variable &lt;STRONG&gt;_N_&lt;/STRONG&gt; holds the number of the current observation read into the program vector, so&lt;STRONG&gt; if _N_ = 1&amp;nbsp;&lt;/STRONG&gt;is true in the first observation read. Neither the variable created by the &lt;STRONG&gt;end=&lt;/STRONG&gt; option nor the automatic variable &lt;STRONG&gt;_N_&lt;/STRONG&gt; are written to the output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the data set options &lt;STRONG&gt;firstobs=&lt;/STRONG&gt; and &lt;STRONG&gt;obs=&lt;/STRONG&gt;&amp;nbsp;control the observations read into the program vector and are applied first, so &lt;STRONG&gt;end=&lt;/STRONG&gt; and &lt;STRONG&gt;_N_&lt;/STRONG&gt;&amp;nbsp;works on the resulting subset. Try the code in the previous post and see what happens.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Mar 2023 10:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865085#M341608</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-03-19T10:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Does the start= option inside of a data step actually exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865115#M341627</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;, if I may, let me continue your thread and&amp;nbsp;add something more.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The firstobs= and ons= works before end= and _N_, but we have to be aware when we are using them in composition with the WHERE statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do x = 1 to 3;
    output;
  end;
run;


data want;
  set have(firstobs=2);
  where x &amp;gt; 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in this case the WHERE cuts "1" from input data set and then the firstobs= cuts "2" from what have left from filtering.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And a note about "start=" one thing is to use "_N_=1" but when we for example are reading several data sets with a single SET statement we can use the CUROBS= option to get info which observation we are reading into PDV, e.g.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A B C;
  do x = 1 to 3;
    output;
  end;
run;

data ABC;
 set A B C curobs=curobs;

 if curobs=1 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So "curobs=1" tests if we are reading the first observation from a give data set (of course if the data set has the first observation, what not always have to be the case).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&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>Sun, 19 Mar 2023 20:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865115#M341627</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-03-19T20:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Does the start= option inside of a data step actually exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865119#M341630</link>
      <description>&lt;P&gt;Let me correct your language.&amp;nbsp; _N_ does not count observations.&amp;nbsp; It counts iterations of the data step.&amp;nbsp; The confusion arises because in the normal simple data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set old;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;they amount to the same thing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But once you get more complicated, say by using DOW loop, they diverge.&amp;nbsp; For example in this data step the value of _N_ can be seen as a count of the number of ID values seen.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.id);
     set old;
     by id;
     total=sum(total,amount)
  end;
  keep id total;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But even in the simple data step you can see that the value of _N_ is different than "the number of observations read in".&amp;nbsp; Most obviously is when it increments beyond the number of observations in the source dataset since such a data step will end at the SET statement and not the RUN statement.&lt;/P&gt;
&lt;PRE&gt;2327  data want;
2328    put _n_= eof= ;
2329    set sashelp.class(obs=2) end=eof;
2330  run;

_N_=1 eof=0
_N_=2 eof=0
_N_=3 eof=1
NOTE: There were 2 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.WANT has 2 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Mar 2023 21:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865119#M341630</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-19T21:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Does the start= option inside of a data step actually exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865149#M341644</link>
      <description>&lt;P&gt;I would go even one step further.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;EM&gt;_N_ does not count observations.&amp;nbsp; It counts iterations of the data step.&lt;/EM&gt;" -&amp;nbsp; _N_ in fact does not counts iterations, it is a placeholder for value of internal iterations counter. In deed, you can modify it and then at the beginning of the new iteration it is automatically updated with current iteration number:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do x = "A", "B", "C";
    output;
  end;
run;

data _null_;
  put "1)" _all_;
  set have;
  put "2)" _all_;

  do _N_ = 1 to 5;
    put _N_= @;
  end;
  put;

  put "3)" _all_;
  put;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    data have;
2      do x = "A", "B", "C";
3        output;
4      end;
5    run;

NOTE: The data set WORK.HAVE has 3 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


6
7    data _null_;
8      put "1)" _all_;
9      set have;
10     put "2)" _all_;
11
12     do _N_ = 1 to 5;
13       put _N_= @;
14     end;
15     put;
16
17     put "3)" _all_;
18     put;
19   run;

1)x=  _ERROR_=0 _N_=1
2)x=A _ERROR_=0 _N_=1
_N_=1 _N_=2 _N_=3 _N_=4 _N_=5
3)x=A _ERROR_=0 _N_=6

1)x=A _ERROR_=0 _N_=2
2)x=B _ERROR_=0 _N_=2
_N_=1 _N_=2 _N_=3 _N_=4 _N_=5
3)x=B _ERROR_=0 _N_=6

1)x=B _ERROR_=0 _N_=3
2)x=C _ERROR_=0 _N_=3
_N_=1 _N_=2 _N_=3 _N_=4 _N_=5
3)x=C _ERROR_=0 _N_=6

1)x=C _ERROR_=0 _N_=4
NOTE: There were 3 observations read from the data set WORK.HAVE.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Very good reading about looping is "The Magnificent DO" article by Paul Dorfman (&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;), link is here: &lt;A href="https://support.sas.com/resources/papers/proceedings13/126-2013.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings13/126-2013.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 10:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865149#M341644</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-03-20T10:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Does the start= option inside of a data step actually exist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865216#M341664</link>
      <description>&lt;P&gt;Cześć Bartku,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're exactly right. Methinks the necessary and sufficient definition could be this:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt; Regardless of its current value, _N_ is assigned the next consecutive natural number every time program control is passed to the top of the DATA step (by the action of the implied loop).&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Thus, since at first program control is at the top of the implied loop, 1 is moved to _N_. The next time program control is passed to the top of the implied loop, 2 is moved to _N_, and so forth. Hence, as you have indicated, the program can assign any numeric value to _N_ between two consecutive returns of program control to the top of the DATA step, yet it has no effect on the new value moved to _N_ at the top of the DATA step from the independent internal counter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps one could say that an internal equivalent of the statement:&lt;/P&gt;
&lt;P&gt;_N_ = monotonic() ;&lt;/P&gt;
&lt;P&gt;is executed at the top of the implied loop.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the plug &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;.&lt;/P&gt;
&lt;P&gt;Pozdrowienia,&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 14:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-the-start-option-inside-of-a-data-step-actually-exist/m-p/865216#M341664</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2023-03-20T14:22:46Z</dc:date>
    </item>
  </channel>
</rss>

