<?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: Question about DO WHILE loop in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851525#M37369</link>
    <description>&lt;P&gt;Why increment the loop counter yourself?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  x = 1.5;
  do i=1 to 5 by X;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 29 Dec 2022 13:57:56 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-12-29T13:57:56Z</dc:date>
    <item>
      <title>Question about DO WHILE loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851433#M37357</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;A sample while loop:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test;
  x = 1.5;
  i=1;
  
  do while (i &amp;lt; 5);
    i = i + x;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result would have 3 observations with i = 5.5 as the 3rd or last observation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is, how do I make sure that my output is excluding the value N in the DO WHILE condition.&amp;nbsp;&lt;/P&gt;&lt;P&gt;do while (i &amp;lt; n)&lt;/P&gt;&lt;P&gt;So, the above would only have 2 observations, with the i = 5.5 observation been excluded.&lt;/P&gt;&lt;P&gt;I am asking this as in general, because it seems it'll always include the last observation where it doesn't meet the condition to break the loop.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2022 22:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851433#M37357</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2022-12-28T22:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Question about DO WHILE loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851457#M37362</link>
      <description>&lt;P&gt;Your code does a test using the value in I but then you first increase I before writing it to the output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1672278184621.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78918iEB57EBAF8308A1A4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1672278184621.png" alt="Patrick_0-1672278184621.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This means the value for I you see in your output is not the value of I that had been used for the current iteration of your test but is the value that will get used in the next iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you write your data to output before you change the value of I then you see what value has actually been used as condition in your do while loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  x = 1.5;
  i=1;
  do while (i &amp;lt; 5);
    output;
    i = i + x;
  end;
run;
proc print data=test;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1672278350129.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78919iB795C0448D784EDA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1672278350129.png" alt="Patrick_1-1672278350129.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Three rows selected looks right to me. If you only want two then change your selection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Dec 2022 01:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851457#M37362</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-12-29T01:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Question about DO WHILE loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851489#M37367</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
x = 1.5;
i = 1 + x;
do while (i &amp;lt; 5);
  output;
  i = i + x;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Dec 2022 07:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851489#M37367</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-29T07:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Question about DO WHILE loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851515#M37368</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  x = 1.5;
  i=1;
  
  do while (1);
    i = i + x;
	if i &amp;gt;= 5 then leave;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Dec 2022 12:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851515#M37368</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-12-29T12:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Question about DO WHILE loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851525#M37369</link>
      <description>&lt;P&gt;Why increment the loop counter yourself?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  x = 1.5;
  do i=1 to 5 by X;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Dec 2022 13:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851525#M37369</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-29T13:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Question about DO WHILE loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851531#M37370</link>
      <description>Great explanation, thank you!</description>
      <pubDate>Thu, 29 Dec 2022 15:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851531#M37370</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2022-12-29T15:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Question about DO WHILE loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851535#M37371</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;That would include the upper boundary. What if this upper boundary would be 5.5?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Dec 2022 15:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851535#M37371</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-12-29T15:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: Question about DO WHILE loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851538#M37372</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;That would include the upper boundary. What if this upper boundary would be 5.5?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Adjust the upper bound as appropriate for whatever you want.&lt;/P&gt;
&lt;P&gt;If you want to exclude the upper bound then do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do index=lowerbound to upperbound-delta by step;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can always also add the WHILE () condition.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do index=lowerbound to upperbound by step while (index&amp;lt;upperbound);&lt;BR /&gt;do&amp;nbsp;index=lowebound&amp;nbsp;by&amp;nbsp;step&amp;nbsp;while&amp;nbsp;(index&amp;lt;upperbound);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Dec 2022 17:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-about-DO-WHILE-loop/m-p/851538#M37372</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-29T17:40:32Z</dc:date>
    </item>
  </channel>
</rss>

