<?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 Loops: why do I get i+1 iterations instead of i ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loops-why-do-I-get-i-1-iterations-instead-of-i/m-p/76508#M16565</link>
    <description>Hi, &lt;BR /&gt;
I submitted this code: &lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;data MyTable;&lt;BR /&gt;
do i=1 to 5;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
and I got&lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;Obs   i&lt;BR /&gt;
  1     &lt;B&gt;6&lt;/B&gt;&lt;/I&gt;.&lt;BR /&gt;
&lt;BR /&gt;
I'm confused : Why do I get 6 and not 5 ??&lt;BR /&gt;
&lt;BR /&gt;
Thank you in advance</description>
    <pubDate>Thu, 22 Oct 2009 15:37:28 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-10-22T15:37:28Z</dc:date>
    <item>
      <title>Loops: why do I get i+1 iterations instead of i ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loops-why-do-I-get-i-1-iterations-instead-of-i/m-p/76508#M16565</link>
      <description>Hi, &lt;BR /&gt;
I submitted this code: &lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;data MyTable;&lt;BR /&gt;
do i=1 to 5;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
and I got&lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;Obs   i&lt;BR /&gt;
  1     &lt;B&gt;6&lt;/B&gt;&lt;/I&gt;.&lt;BR /&gt;
&lt;BR /&gt;
I'm confused : Why do I get 6 and not 5 ??&lt;BR /&gt;
&lt;BR /&gt;
Thank you in advance</description>
      <pubDate>Thu, 22 Oct 2009 15:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loops-why-do-I-get-i-1-iterations-instead-of-i/m-p/76508#M16565</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-22T15:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Loops: why do I get i+1 iterations instead of i ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loops-why-do-I-get-i-1-iterations-instead-of-i/m-p/76509#M16566</link>
      <description>Because the loop incremented the value of i until it was greater than 5 (6) and then the implied OUTPUT statement that occurs before the RUN statement executed.&lt;BR /&gt;
I think you want this:&lt;BR /&gt;
-----------------------------&lt;BR /&gt;
data MyTable;&lt;BR /&gt;
do i=1 to 5;&lt;BR /&gt;
OUTPUT;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
----------------------------&lt;BR /&gt;
When you explicitly specify an OUTPUT statement, it overrides the implied OUTPUT statement that occurs before the RUN statement, so on the value of i that occured inside the loop are output;&lt;BR /&gt;
Hope that was clear.</description>
      <pubDate>Thu, 22 Oct 2009 15:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loops-why-do-I-get-i-1-iterations-instead-of-i/m-p/76509#M16566</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2009-10-22T15:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Loops: why do I get i+1 iterations instead of i ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loops-why-do-I-get-i-1-iterations-instead-of-i/m-p/76510#M16567</link>
      <description>Yes ok thank you &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Thu, 22 Oct 2009 17:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loops-why-do-I-get-i-1-iterations-instead-of-i/m-p/76510#M16567</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-22T17:30:02Z</dc:date>
    </item>
  </channel>
</rss>

