<?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 iterative statement expression evaluation? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-iterative-statement-expression-evaluation/m-p/197808#M266560</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The main difference between &lt;STRONG&gt;while &lt;/STRONG&gt; and &lt;STRONG&gt;until &lt;/STRONG&gt; is&lt;/P&gt;&lt;P&gt;In &lt;STRONG&gt; while : &lt;/STRONG&gt;the loop stops iterating when the condition is false&lt;/P&gt;&lt;P&gt;In &lt;STRONG&gt; until : &lt;/STRONG&gt; the loop stops iterating when the condition is true.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example : you want to display 5 consecutive numbers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data Sample;&lt;/P&gt;&lt;P&gt;i = 1;&amp;nbsp; &lt;/P&gt;&lt;P&gt;do while (i &amp;lt;= 5);&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;i+1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above program we are initializing a value (1) to the variable i. So i = 1.&lt;/P&gt;&lt;P&gt;now the do loop starts.&lt;/P&gt;&lt;P&gt;checks the condition i &amp;lt;= 5 i.e 1 &amp;lt;=5 .&lt;/P&gt;&lt;P&gt;the condition is true.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;.now it enters the loop and executes the statements.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;.first it puts the value of i to the dataset and then the value of i will be incremented.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;now the value of i is 2.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;it goes to the top of the loop and again checks the condition i&amp;lt;=5 i.e i&amp;lt;=2&lt;/P&gt;&lt;P&gt;the condition is true. so step 1 and 2 are executed and now the value of i becomes 3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;it goes to the top of the loop and again checks the condition i&amp;lt;=5 i.e i&amp;lt;=3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;the condition is true. so step 1 and 2 are executed and now the value of i becomes 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;it goes to the top of the loop and again checks the condition i&amp;lt;=5 i.e i&amp;lt;=4&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;the condition is true. so step 1 and 2 are executed and now the value of i becomes 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;it goes to the top of the loop and again checks the condition i&amp;lt;=5 i.e i&amp;lt;=5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;the condition is true. so step 1 and 2 are executed and now the value of i becomes 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;it goes to the top of the loop and again checks the condition i&amp;lt;=5 i.e i&amp;lt;=6... the condition is false so it comes out of the loop and then executes the remaining statements after &lt;STRONG&gt;end.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;The next statement is output.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Now again the value of i is inserted to the Dataset.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;After terminating from the do loop the value of i is 6. So 6 will be inserted in the dataset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;If we dont insert the output statement after the do loop then only 5 observation will be there in the dataset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;So the while loop executes until the condition is false.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;In the same way until executes until the condion is true. &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;The only change in the code is in the condition &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;for while&lt;/STRONG&gt; : &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;do while (i&amp;lt;=5&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ------------ Loop will be iterated until the value is less than or equal to 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;----;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;&lt;STRONG&gt;for until&lt;/STRONG&gt; :&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;do until(i&amp;gt;5);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ------------ Loop will be iterated until the value is greater than 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;-----;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;end;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 Jul 2015 08:27:43 GMT</pubDate>
    <dc:creator>MadhuKorni</dc:creator>
    <dc:date>2015-07-08T08:27:43Z</dc:date>
    <item>
      <title>Do loop iterative statement expression evaluation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-iterative-statement-expression-evaluation/m-p/197807#M266559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I am finding it difficult to understand &lt;STRONG&gt;"how and when"&lt;/STRONG&gt; the while or until expression is evaluated or checked in a iterative do loop statement. The documentation says something the optional while or until only evaluates when the index variable value happens to be the last item or something like that and in another google search I found either the index or the expression whichever comes first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do index-variable= start to stop by increment while(expression) or until(expression);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone please clarify my understanding. Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 06:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-iterative-statement-expression-evaluation/m-p/197807#M266559</guid>
      <dc:creator>Andygray</dc:creator>
      <dc:date>2015-07-08T06:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop iterative statement expression evaluation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-iterative-statement-expression-evaluation/m-p/197808#M266560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The main difference between &lt;STRONG&gt;while &lt;/STRONG&gt; and &lt;STRONG&gt;until &lt;/STRONG&gt; is&lt;/P&gt;&lt;P&gt;In &lt;STRONG&gt; while : &lt;/STRONG&gt;the loop stops iterating when the condition is false&lt;/P&gt;&lt;P&gt;In &lt;STRONG&gt; until : &lt;/STRONG&gt; the loop stops iterating when the condition is true.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example : you want to display 5 consecutive numbers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data Sample;&lt;/P&gt;&lt;P&gt;i = 1;&amp;nbsp; &lt;/P&gt;&lt;P&gt;do while (i &amp;lt;= 5);&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;i+1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above program we are initializing a value (1) to the variable i. So i = 1.&lt;/P&gt;&lt;P&gt;now the do loop starts.&lt;/P&gt;&lt;P&gt;checks the condition i &amp;lt;= 5 i.e 1 &amp;lt;=5 .&lt;/P&gt;&lt;P&gt;the condition is true.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;.now it enters the loop and executes the statements.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;.first it puts the value of i to the dataset and then the value of i will be incremented.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;now the value of i is 2.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;it goes to the top of the loop and again checks the condition i&amp;lt;=5 i.e i&amp;lt;=2&lt;/P&gt;&lt;P&gt;the condition is true. so step 1 and 2 are executed and now the value of i becomes 3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;it goes to the top of the loop and again checks the condition i&amp;lt;=5 i.e i&amp;lt;=3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;the condition is true. so step 1 and 2 are executed and now the value of i becomes 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;it goes to the top of the loop and again checks the condition i&amp;lt;=5 i.e i&amp;lt;=4&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;the condition is true. so step 1 and 2 are executed and now the value of i becomes 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;it goes to the top of the loop and again checks the condition i&amp;lt;=5 i.e i&amp;lt;=5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;the condition is true. so step 1 and 2 are executed and now the value of i becomes 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;it goes to the top of the loop and again checks the condition i&amp;lt;=5 i.e i&amp;lt;=6... the condition is false so it comes out of the loop and then executes the remaining statements after &lt;STRONG&gt;end.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;The next statement is output.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Now again the value of i is inserted to the Dataset.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;After terminating from the do loop the value of i is 6. So 6 will be inserted in the dataset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;If we dont insert the output statement after the do loop then only 5 observation will be there in the dataset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;So the while loop executes until the condition is false.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;In the same way until executes until the condion is true. &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;The only change in the code is in the condition &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;for while&lt;/STRONG&gt; : &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;do while (i&amp;lt;=5&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ------------ Loop will be iterated until the value is less than or equal to 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;----;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;&lt;STRONG&gt;for until&lt;/STRONG&gt; :&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;do until(i&amp;gt;5);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ------------ Loop will be iterated until the value is greater than 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;-----;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;end;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 08:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-iterative-statement-expression-evaluation/m-p/197808#M266560</guid>
      <dc:creator>MadhuKorni</dc:creator>
      <dc:date>2015-07-08T08:27:43Z</dc:date>
    </item>
  </channel>
</rss>

