<?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/501408#M133682</link>
    <description>&lt;P&gt;I can see that, but when you do add output as in the first case, i=5 in the last observation&lt;/P&gt;</description>
    <pubDate>Thu, 04 Oct 2018 10:07:11 GMT</pubDate>
    <dc:creator>vstorme</dc:creator>
    <dc:date>2018-10-04T10:07:11Z</dc:date>
    <item>
      <title>do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501357#M133670</link>
      <description>&lt;P&gt;Dear SAS users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a basic question. Why is i 5.5&amp;nbsp;upon the following code when the output statement is not given:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
do i = 1 to 5 by 0.5;
   y = i**2; 
   output;
end;
run;
proc print data = A;
run;

data A;
do i = 1 to 5 by 0.5;
   y = i**2; 
end;
run;
proc print data = A;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Oct 2018 07:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501357#M133670</guid>
      <dc:creator>vstorme</dc:creator>
      <dc:date>2018-10-04T07:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501361#M133672</link>
      <description>&lt;P&gt;Read the manual!&lt;/P&gt;
&lt;P&gt;i is incremented at the end of the loop to 5.5, however as that is over the top boundary for the do loop, the do loop then exits.&amp;nbsp; The incremenetor will always (upon complete run) be one iteration count above the upper bound.&amp;nbsp; Its a bit like saying:&lt;/P&gt;
&lt;PRE&gt;set i to lower limit
start
is i over upper limit, no then do
  ...
increment i by one iteration and return to start&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Oct 2018 07:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501361#M133672</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-04T07:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501362#M133673</link>
      <description>&lt;P&gt;I suppose you mean your last data step. The thing is this: if there is no explicit OUTPUT statement in a data step, SAS puts an implicit output statement at the end of the data step. After the loop has run, I=5.5, and that value is output. But for Y you will get 4.5**2, as that was the last assignment inside the loop.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 07:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501362#M133673</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-04T07:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501379#M133677</link>
      <description>&lt;P&gt;In code,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i = 1 to 5 by 0.5;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;translates to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;i = 1;
do while (i &amp;lt;= 5);
  i + 0.5;
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Oct 2018 08:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501379#M133677</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-04T08:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501408#M133682</link>
      <description>&lt;P&gt;I can see that, but when you do add output as in the first case, i=5 in the last observation&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 10:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501408#M133682</guid>
      <dc:creator>vstorme</dc:creator>
      <dc:date>2018-10-04T10:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501412#M133684</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/27680"&gt;@vstorme&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I can see that, but when you do add output as in the first case, i=5 in the last observation&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's because the implicit&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;i + 0.5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;comes after the execution of the output statement, and no implicit output is done after the do loop finishes.&lt;/P&gt;
&lt;P&gt;Do this for reference:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
do i = 1 to 5 by 0.5;
   y = i**2; 
   output;
  put i=;
end;
put i=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Oct 2018 10:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop/m-p/501412#M133684</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-04T10:30:44Z</dc:date>
    </item>
  </channel>
</rss>

