<?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: Do Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462817#M117862</link>
    <description>&lt;P&gt;The do loop&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; DO index=1 to 5 by 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x=index;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tells SAS to&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Assess INDEX at the top of the loop to see whether index satisfies the condition needed to run another iteration.&lt;/LI&gt;
&lt;LI&gt;Increments INDEX by 2&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;at the bottom of the loop.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So when index=5, the loop runs an iteration (and x=5).&amp;nbsp; At the end of that iteration&amp;nbsp;INDEX is incremented to 7, then SAS goes to the top for assessment of index.&amp;nbsp; It exceeds 5, so the do loops are finished, leaving X=5.&lt;/P&gt;</description>
    <pubDate>Wed, 16 May 2018 19:28:04 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2018-05-16T19:28:04Z</dc:date>
    <item>
      <title>Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462757#M117850</link>
      <description>&lt;P&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;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q) Upon completion of execution, what are the values of the variables X and Index in the SAS data set&lt;BR /&gt;named WORK.LOOP?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The answer given is&amp;nbsp;X = 5, Index = 7&lt;/P&gt;&lt;P&gt;Can someone kindly enlighten me?&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 15:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462757#M117850</guid>
      <dc:creator>cow240</dc:creator>
      <dc:date>2018-05-16T15:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462758#M117851</link>
      <description>Run the step yourself and insert PUT statements or using data step debugger to follow variable value assignments.</description>
      <pubDate>Wed, 16 May 2018 16:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462758#M117851</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-05-16T16:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462759#M117852</link>
      <description>&lt;P&gt;Using put statements carefully between statements helps us to know what's happening during each iteration and why(logic aka the loop's exit)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&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;&lt;STRONG&gt;put x= index=;&lt;/STRONG&gt;&lt;BR /&gt;end;&lt;BR /&gt;&lt;STRONG&gt;put index=;&lt;/STRONG&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;put x= index=;--&amp;gt;&lt;/STRONG&gt;X=1 Index=1&lt;BR /&gt;&lt;STRONG&gt;put x= index=;--&amp;gt;&lt;/STRONG&gt;X=3 Index=3&lt;BR /&gt;&lt;STRONG&gt;put x= index=;--&amp;gt;&lt;/STRONG&gt;X=5 Index=5&lt;BR /&gt;&lt;STRONG&gt;put index=; --&amp;gt;&lt;/STRONG&gt;Index=7&amp;nbsp; loops exit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this help at all?&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 16:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462759#M117852</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-16T16:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462761#M117853</link>
      <description>Thank you for your replies. Apologies for the newbie questions as im new to SAS. I just thought that intuitively, it should stop at 5 since it exits at 5. I guess I have a lot to learn!</description>
      <pubDate>Wed, 16 May 2018 16:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462761#M117853</guid>
      <dc:creator>cow240</dc:creator>
      <dc:date>2018-05-16T16:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462762#M117854</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203912"&gt;@cow240&lt;/a&gt;wrote:&lt;BR /&gt;Thank you for your replies. Apologies for the newbie questions as im new to SAS. I just thought that intuitively, it should stop at 5 since it exits at 5. I guess I have a lot to learn!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;No need for&amp;nbsp;&lt;SPAN&gt;Apologies&amp;nbsp;. There aint somebody who is more dumb than me when i started learning sas. Cheers!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 16:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462762#M117854</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-16T16:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462779#M117858</link>
      <description>&lt;P&gt;The question is very trivial and basic, however you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203912"&gt;@cow240&lt;/a&gt;&amp;nbsp;could mark one of the answer as accepted&amp;nbsp; and answered&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 17:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462779#M117858</guid>
      <dc:creator>MarkWik</dc:creator>
      <dc:date>2018-05-16T17:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462817#M117862</link>
      <description>&lt;P&gt;The do loop&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; DO index=1 to 5 by 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x=index;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tells SAS to&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Assess INDEX at the top of the loop to see whether index satisfies the condition needed to run another iteration.&lt;/LI&gt;
&lt;LI&gt;Increments INDEX by 2&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;at the bottom of the loop.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So when index=5, the loop runs an iteration (and x=5).&amp;nbsp; At the end of that iteration&amp;nbsp;INDEX is incremented to 7, then SAS goes to the top for assessment of index.&amp;nbsp; It exceeds 5, so the do loops are finished, leaving X=5.&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 19:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop/m-p/462817#M117862</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-05-16T19:28:04Z</dc:date>
    </item>
  </channel>
</rss>

