<?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/465662#M285251</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me to understand why the final output x= 5 index = 7 appear?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;data work.loop;&lt;BR /&gt;	x = 0;&lt;BR /&gt;	do index = 1 to 5 by 2;&lt;BR /&gt;	x = index;&lt;BR /&gt;	output;&lt;BR /&gt;	end;&lt;BR /&gt;	output;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 383px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20826iCEC19E8EBCA0F2BF/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 29 May 2018 12:08:03 GMT</pubDate>
    <dc:creator>vincentgoh88</dc:creator>
    <dc:date>2018-05-29T12:08:03Z</dc:date>
    <item>
      <title>Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465662#M285251</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me to understand why the final output x= 5 index = 7 appear?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;data work.loop;&lt;BR /&gt;	x = 0;&lt;BR /&gt;	do index = 1 to 5 by 2;&lt;BR /&gt;	x = index;&lt;BR /&gt;	output;&lt;BR /&gt;	end;&lt;BR /&gt;	output;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 383px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20826iCEC19E8EBCA0F2BF/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 12:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465662#M285251</guid>
      <dc:creator>vincentgoh88</dc:creator>
      <dc:date>2018-05-29T12:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465663#M285252</link>
      <description>&lt;P&gt;Just simply follow the logic:&lt;/P&gt;
&lt;PRE&gt;	do index = 1 to 5 by 2;&lt;BR /&gt;	x = index;&lt;BR /&gt;	output;&lt;BR /&gt;	end;&lt;BR /&gt;	output;&lt;/PRE&gt;
&lt;P&gt;Index starts at 1, x is set to it.&amp;nbsp; Then it is output&lt;/P&gt;
&lt;P&gt;Then 3, x is set to it.&amp;nbsp; Then it is output&lt;/P&gt;
&lt;P&gt;Then 5, x is set to it, then it is output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then index becomes 7, which does not work in the do, so the do loop is jumped, and then next step is output, which outputs the 7 record.&amp;nbsp; X remains as 5, as the part in the do loop is not executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 12:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465663#M285252</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-29T12:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465664#M285253</link>
      <description>Thanks!</description>
      <pubDate>Tue, 29 May 2018 12:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465664#M285253</guid>
      <dc:creator>vincentgoh88</dc:creator>
      <dc:date>2018-05-29T12:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465668#M285254</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The do loop continues looping until the upper limit is exceeded, so after the loop has processed the index&amp;nbsp;of 5, index is increased by 2 which becomes 7 which exceeds the upper limit of the loop and so it is not executed again; x is not reassigned again so it is left with its last value of 5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 12:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465668#M285254</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-05-29T12:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465680#M285255</link>
      <description>&lt;P&gt;After DO LOOP ,index will +2 by itself , therefore, the last index is 7 .&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 12:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465680#M285255</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-29T12:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465686#M285256</link>
      <description>&lt;P&gt;Basically all languages that I know implement iterative loops like that.&lt;/P&gt;
&lt;P&gt;Only loops where the "index variable" is set from a list (eg see "for" in UNIX shell scripting) terminate differently.&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 13:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/465686#M285256</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-29T13:17:02Z</dc:date>
    </item>
  </channel>
</rss>

