<?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: SAS Data Step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806502#M317767</link>
    <description>&lt;P&gt;When SAS reads from a SAS data set (such as using a SET statement), it automatically retains all variables coming from the SAS data set.&amp;nbsp; They are never re-set to missing.&lt;/P&gt;</description>
    <pubDate>Thu, 07 Apr 2022 13:24:16 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2022-04-07T13:24:16Z</dc:date>
    <item>
      <title>SAS Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806485#M317754</link>
      <description>&lt;P&gt;data one;&lt;BR /&gt;if _n_ = 1 then do i = 1 to 4;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;end;&lt;BR /&gt;value = _n_;&lt;BR /&gt;output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to understand why there are two outputs. As per the logic, there should be one output, when _n_ = 2, all the column values should go missing. then why the first observation is being retained?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 12:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806485#M317754</guid>
      <dc:creator>SAIKDE</dc:creator>
      <dc:date>2022-04-07T12:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806492#M317756</link>
      <description>&lt;P&gt;Maxim 2: Read the Log.&lt;/P&gt;
&lt;PRE&gt; 69         data one;
 70         if _n_ = 1 then do i = 1 to 4;
 71         set sashelp.class;
 72         end;
 73         value = _n_;
 74         output;
 75         run;
 
 &lt;FONT color="#FF0000"&gt;NOTE: DATA STEP stopped due to looping.&lt;/FONT&gt;
 NOTE: There were 4 observations read from the data set SASHELP.CLASS.
&lt;/PRE&gt;
&lt;P&gt;Without the data step being so intelligent, this code would run forever, with great CPU consumption.&lt;/P&gt;
&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;In the first iteration, it reads 4 observations, and outputs the 4th.&lt;/P&gt;
&lt;P&gt;In the next (and every other possible iteration), nothing is read, preventing an end-of-dataset from terminating the step. But the data step itself realizes &lt;EM&gt;at the end of the second iteration&lt;/EM&gt; that it would never reach an end (because the dataset observation pointer did not change) and shuts down on its own. This happens&amp;nbsp;&lt;EM&gt;after&lt;/EM&gt; the explicit OUTPUT has been executed for a second time; since all variables coming from input datasets are automatically retained, the observation looks identical to the first, with the exception of i. This variable is not from a dataset, and is therefore set to missing at the beginning of a data step iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, even if you omit the explicit OUTPUT, the implicit output will also happen twice before the data step stops.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 12:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806492#M317756</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-07T12:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806498#M317763</link>
      <description>&lt;P&gt;The question is what are you attempting to achieve?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 13:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806498#M317763</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-04-07T13:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806502#M317767</link>
      <description>&lt;P&gt;When SAS reads from a SAS data set (such as using a SET statement), it automatically retains all variables coming from the SAS data set.&amp;nbsp; They are never re-set to missing.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 13:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806502#M317767</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-04-07T13:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806504#M317768</link>
      <description>&lt;P&gt;On the second iteration the variable _N_ will be set to 2 and variables I and VALUE that are defined by the data step will be set to missing.&amp;nbsp; But the variables coming from the input dataset are NOT set to missing.&amp;nbsp; That is how the data step works.&amp;nbsp; It is what makes one to many merges work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only want the 4th observation then use some other method.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data four;
  set sashelp.class (obs=4 firstobs=4);
run;

data four;
  set sashelp.class;
  if _n_=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Apr 2022 13:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806504#M317768</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-07T13:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806511#M317771</link>
      <description>&lt;P&gt;You are using a conditional SET statement.&amp;nbsp; As explained by others, variables read in by a SET (or a MERGE) statement are not automatically reset to missing, and only change values when they are overwritten by the next SET or MERGE accessing those variables.&amp;nbsp; But in your case, there is no use of SET except for _N_=1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, you could take on the activity of resetting to missing on your own, as below - which would generate the missing values you expected for the second observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  if _n_ = 1 then do i = 1 to 4;
    set sashelp.class;
  end;
  value = _n_;
  output;
  call missing(of _all_);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 13:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806511#M317771</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-07T13:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806568#M317814</link>
      <description>&lt;LI-CODE lang="sas"&gt;four' one;
  if _n_ = 1 then do i = 1 to 4;
    set sashelp.class;
  end;
  out = _n_;
  output;
  run(of _all_);
run;&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 07 Apr 2022 16:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806568#M317814</guid>
      <dc:creator>dexcort2020</dc:creator>
      <dc:date>2022-04-07T16:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806575#M317820</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/406226"&gt;@dexcort2020&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;LI-CODE lang="sas"&gt;four' one;
  if _n_ = 1 then do i = 1 to 4;
    set sashelp.class;
  end;
  out = _n_;
  output;
  run(of _all_);
run;&lt;/LI-CODE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;??????????????????&lt;/P&gt;
&lt;P&gt;Not basic SAS syntax, so where is this coming from?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 17:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Data-Step/m-p/806575#M317820</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-07T17:04:00Z</dc:date>
    </item>
  </channel>
</rss>

