<?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 while in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185918#M265622</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Values N=11 or N=12 are the loop terminators when condition was evaluated as false. In your dataset square you will have the right numbers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Oct 2014 19:52:49 GMT</pubDate>
    <dc:creator>stat_sas</dc:creator>
    <dc:date>2014-10-15T19:52:49Z</dc:date>
    <item>
      <title>do while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185916#M265620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: SASMonospaceBT-Roman;"&gt;Hi guys, I thought Square is the same thing as n**2 because they are just the opposite side of an equation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: SASMonospaceBT-Roman;"&gt;but I really cannot figure our why it shows different result when I run the following two codes;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data square;&lt;/P&gt;&lt;P&gt;do n = 1 to 1000 while (&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;n**2&lt;/STRONG&gt;&lt;/SPAN&gt; le 100);&lt;/P&gt;&lt;P&gt;Square = n**2;&lt;/P&gt;&lt;P&gt;output;&lt;SPAN style="font-size: 10pt; font-family: SASMonospaceBT-Roman;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;put n= ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The result is N=11&amp;nbsp; &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data square;&lt;/P&gt;&lt;P&gt;do n = 1 to 1000 while (&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;Square&lt;/STRONG&gt;&lt;/SPAN&gt; le 100);&lt;/P&gt;&lt;P&gt;Square = n**2;&lt;/P&gt;&lt;P&gt;output;&lt;SPAN style="font-size: 10pt; font-family: SASMonospaceBT-Roman;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;end;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;put n=&amp;nbsp; ;&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;The result is N=12&amp;nbsp; :smileyshocked:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Square&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&lt;/P&gt;&lt;P&gt;11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 121&lt;/P&gt;&lt;P&gt;12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 144&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 19:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185916#M265620</guid>
      <dc:creator>chouchou</dc:creator>
      <dc:date>2014-10-15T19:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: do while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185917#M265621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Has nothing to do with the ** but the behavior of DO WHILE and evaluation of Missing values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DO while evaluates at the start of the loop. In the first case when n**2 is used n has a value (1)&amp;nbsp; and is evaluated. With the second case Square does not have any value until AFTER the first execution of the comparison (Square le 100) and since Missing is Always less than any given value it evaluates as true. Do a proc print after each of the data steps and you'll see that behavior and the second version being one step "later" for values of Square.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 19:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185917#M265621</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-10-15T19:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: do while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185918#M265622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Values N=11 or N=12 are the loop terminators when condition was evaluated as false. In your dataset square you will have the right numbers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 19:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185918#M265622</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-10-15T19:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: do while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185919#M265623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link active_link" data-avatarid="2168" data-externalid="" data-presence="null" data-userid="823607" data-username="chouchou" href="https://communities.sas.com/people/chouchou" id="jive-82360728783651653284186"&gt;chouchou&lt;/A&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using this, I am getting 11 values in dataset square.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data square;&lt;BR /&gt;do n = 1 to 1000 while (Square le 100);&lt;BR /&gt;Square = n**2;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=square;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 20:11:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185919#M265623</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-10-15T20:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: do while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185920#M265624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But since the OP was Putting the value of n After the execution of the loop it has n=12. The do set the value of N then evaluates Square. So after leaving the loop n is one larger.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 20:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185920#M265624</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-10-15T20:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: do while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185921#M265625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@ &lt;SPAN class="j-post-author "&gt;&lt;STRONG&gt;&lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link" data-avatarid="-1" data-externalid="" data-presence="null" data-userid="260198" data-username="ballardw" href="https://communities.sas.com/people/ballardw" id="jive-26019828784581002171186"&gt;ballardw&lt;/A&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;: Agreed, dataset square will have 11 values and n will have maximum value of 11 while square will be 121 against this. After the termination of while loop now n has value of 12 which is being used in put statement and log shown in log as 12. If we use following, it will give us wrong numbers&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data square;&lt;BR /&gt;do n = 1 to 1000 while (Square le 100);&lt;BR /&gt;Square = n**2;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=square;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 20:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185921#M265625</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-10-15T20:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: do while</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185922#M265626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Because you are referencing the square of different values of N in the WHILE () condition.&lt;/P&gt;&lt;P&gt;In the first WHILE(n**2 &amp;lt;= 100) you are referencing the N that you just incremented and in the second WHILE(square&amp;lt;=100) you are referencing the square of the N from the previous iteration of the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The value AFTER the loop is larger than the value in the last iteration of the loop because you are using a WHILE condition instead of an UNTIL condition.&lt;/P&gt;&lt;P&gt;Try :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;do n = 1 to 1000 until (&lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5em; color: #ff0000; font-size: 10pt; font-style: inherit; background-color: #ffffff; font-family: inherit;"&gt;&lt;STRONG&gt;n**2&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; &amp;gt; 100);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;or &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;do n = 1 to 1000 until (&lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5em; color: #ff0000; font-size: 10pt; font-style: inherit; background-color: #ffffff; font-family: inherit;"&gt;&lt;STRONG&gt;square&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; &amp;gt; 100);&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Oct 2014 00:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-while/m-p/185922#M265626</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-10-16T00:10:06Z</dc:date>
    </item>
  </channel>
</rss>

