<?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 do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240063#M44254</link>
    <description>&lt;PRE&gt;data test;
  do i = 1 to 10;
  N=_n_;
  output;
  end;
run;

data test;
  do i = 1 to 10;
  output;
  N=_n_;
  end;
run;&lt;/PRE&gt;&lt;P&gt;I am comparing these programs. The second program has first missing N. &amp;nbsp;My impression is &amp;nbsp;that do loop is executing on the first implicit loop of the data test. &amp;nbsp;That is why N is 1 for all observations. I am not sure why second &amp;nbsp;progam creates first missing N.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Dec 2015 17:56:36 GMT</pubDate>
    <dc:creator>SAS_inquisitive</dc:creator>
    <dc:date>2015-12-18T17:56:36Z</dc:date>
    <item>
      <title>do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240063#M44254</link>
      <description>&lt;PRE&gt;data test;
  do i = 1 to 10;
  N=_n_;
  output;
  end;
run;

data test;
  do i = 1 to 10;
  output;
  N=_n_;
  end;
run;&lt;/PRE&gt;&lt;P&gt;I am comparing these programs. The second program has first missing N. &amp;nbsp;My impression is &amp;nbsp;that do loop is executing on the first implicit loop of the data test. &amp;nbsp;That is why N is 1 for all observations. I am not sure why second &amp;nbsp;progam creates first missing N.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 17:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240063#M44254</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-18T17:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240064#M44255</link>
      <description>You output the observation to the data set BEFORE you assign the value to N so it's missing for the first iteration.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Dec 2015 17:57:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240064#M44255</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-18T17:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240066#M44256</link>
      <description>&lt;P&gt;From the documentation: _N_ is initially set to 1. Each time the DATA step loops past the DATA statement, the variable _N_ increments by 1. The value of _N_ represents the number of times the DATA step has iterated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you do not have a set statment bringing in data then the Data step is only interated once so _n_ is 1.&lt;/P&gt;
&lt;P&gt;The rest is timing.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 18:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240066#M44256</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-12-18T18:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240068#M44257</link>
      <description>&lt;P&gt;Thanks, Reeza and ballardw. &amp;nbsp;Is there any exmple of &amp;nbsp;explicit loop and implicit loop working &amp;nbsp;together? &amp;nbsp;I have heard about dow-loop, I wonder if it is example of interplay of inner and outer loop.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 21:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240068#M44257</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-18T21:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240107#M44271</link>
      <description>I think I came up with an example.&lt;BR /&gt;&lt;BR /&gt;data test;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;do i=1 to 5;&lt;BR /&gt;N=_n_;&lt;BR /&gt;output;&lt;BR /&gt;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;I created this dow-loop example by putting set inside do group which does not quite make sense.&lt;BR /&gt;&lt;BR /&gt;data test;&lt;BR /&gt;do i=1 to 5;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;output&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Dec 2015 21:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240107#M44271</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-18T21:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240116#M44273</link>
      <description>&lt;P&gt;Try this and be prepared to be almost amazed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data test;
   do i=1 to 5;
      set sashelp.class;
      n=_n_;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Dec 2015 21:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240116#M44273</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-12-18T21:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240120#M44274</link>
      <description>&lt;P&gt;looks like explicit do loop is taking control of implicit (inner loop). I thought _n_ should be 1 to 19.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 21:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240120#M44274</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-18T21:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240122#M44275</link>
      <description>&lt;P&gt;It shows that SET is an executeable statment that can be conditionally executed, for instead use one data set and condtionally bring in values from another data set, interleave two or more datasets, use a variable in one data set to controll how many records are brought from another while repeating the values from the first set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All kinds of ways to mix things up. Also the reason why you'll find cautions about using _n_ as counter for number of records. _n_ will work fine for single datasets or a single Set with multiple data sets. But as soon as you have 2 or more Set statements the reliability of _n_ to tell you the number of records goes way down.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 22:02:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/240122#M44275</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-12-18T22:02:44Z</dc:date>
    </item>
  </channel>
</rss>

