<?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 the do loop and output statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48071#M12964</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;art297, I see&amp;nbsp; the reason now. thank you! &lt;/P&gt;&lt;P&gt;the example you gave really is really helpful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 13 Aug 2011 17:34:13 GMT</pubDate>
    <dc:creator>gxu</dc:creator>
    <dc:date>2011-08-13T17:34:13Z</dc:date>
    <item>
      <title>the do loop and output statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48069#M12962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a very basic question about the do loop and output statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I learned from "the little sas book" that if I put an "output" statement explicitly in the do loop, then I will get several observations.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;*******************&lt;/P&gt;&lt;P&gt;data generate;&lt;/P&gt;&lt;P&gt;do x=1 to 6;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; y=x **2;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;*****************&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then I will get a data set with 6 observations and 2 variables (there is no problem for this part)&lt;/P&gt;&lt;P&gt;**********************&lt;/P&gt;&lt;P&gt;obs&amp;nbsp; x&amp;nbsp;&amp;nbsp; y&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp; 36&lt;/P&gt;&lt;P&gt;*********************&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I remove the ouput statement, according to the book, it will output only one observation.&amp;nbsp; I expected to get &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;obs&amp;nbsp; x&amp;nbsp; y&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp; 36&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;however, the result is: &lt;/P&gt;&lt;P&gt;obs x y&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 7 36&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am confused about the result of x,&amp;nbsp; why it's 7 instead of 6?&amp;nbsp; will the variable in do loop always increase even if the loop ends?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will appreciate your comments. thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Aug 2011 15:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48069#M12962</guid>
      <dc:creator>gxu</dc:creator>
      <dc:date>2011-08-13T15:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: the do loop and output statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48070#M12963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the statement you used, x=1 to 6, 6 only represented the stop condition.&amp;nbsp; I.e., the loop stopped when x became greater than 6 and, since you didn't specify an increment (i.e., a by value), it incremented each loop by 1.&amp;nbsp; If you don't use the from,to form of the do statement, you can get it so that it won't increment beyond the specified values.&amp;nbsp; E.g.,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt; do count=1,2,3,4,5,6;&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Aug 2011 15:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48070#M12963</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-08-13T15:42:50Z</dc:date>
    </item>
    <item>
      <title>the do loop and output statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48071#M12964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;art297, I see&amp;nbsp; the reason now. thank you! &lt;/P&gt;&lt;P&gt;the example you gave really is really helpful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Aug 2011 17:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48071#M12964</guid>
      <dc:creator>gxu</dc:creator>
      <dc:date>2011-08-13T17:34:13Z</dc:date>
    </item>
    <item>
      <title>the do loop and output statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48072#M12965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can have it both ways. Use the TO/BY spec along with an UNTIL condtion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier New;"&gt;&lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; test;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier New;"&gt;&lt;SPAN style="color: #0000ff;"&gt;do&lt;/SPAN&gt; count=&lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;TO&lt;/SPAN&gt; &lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;6&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;UNTIL&lt;/SPAN&gt; (count EQ &lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;6&lt;/STRONG&gt;&lt;/SPAN&gt;);&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier New; color: #0000ff;"&gt;end&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier New; color: #0000ff;"&gt;output&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier New; color: #000080;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;P&gt;art297 wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the statement you used, x=1 to 6, 6 only represented the stop condition.&amp;nbsp; I.e., the loop stopped when x became greater than 6 and, since you didn't specify an increment (i.e., a by value), it incremented each loop by 1.&amp;nbsp; If you don't use the from,to form of the do statement, you can get it so that it won't increment beyond the specified values.&amp;nbsp; E.g.,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt; do count=1,2,3,4,5,6;&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;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Aug 2011 22:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48072#M12965</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2011-08-13T22:27:36Z</dc:date>
    </item>
    <item>
      <title>the do loop and output statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48073#M12966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It might help to see it using "putlog" as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data generate;&lt;/P&gt;&lt;P&gt;do x=1 to 6;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; y=x **2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; putlog "inner " _all_;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;putlog "outer " _all_;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've marked the two entries of putlog to show whether they are inside or outside the loop.&amp;nbsp; This gives the below output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;inner x=1 y=1 _ERROR_=0 _N_=1&lt;/P&gt;&lt;P&gt;inner x=2 y=4 _ERROR_=0 _N_=1&lt;/P&gt;&lt;P&gt;inner x=3 y=9 _ERROR_=0 _N_=1&lt;/P&gt;&lt;P&gt;inner x=4 y=16 _ERROR_=0 _N_=1&lt;/P&gt;&lt;P&gt;inner x=5 y=25 _ERROR_=0 _N_=1&lt;/P&gt;&lt;P&gt;inner x=6 y=36 _ERROR_=0 _N_=1&lt;/P&gt;&lt;P&gt;outer x=7 y=36 _ERROR_=0 _N_=1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You only had output in place of the "inner" putlog, hence you get 6 rows of output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As Art explained, variable X is increased one more time but the code inside your loop does not execute as the loop as now exceeded its end condition.&amp;nbsp; In your original code then, neither your output line, or calculation of Y run, hence Y remains at its previous value of 36 and the row with x=7 is not output.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 11:43:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48073#M12966</guid>
      <dc:creator>DF</dc:creator>
      <dc:date>2011-08-15T11:43:28Z</dc:date>
    </item>
    <item>
      <title>the do loop and output statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48074#M12967</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DF, Howles, thank you very much for providing the answers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 17:38:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/the-do-loop-and-output-statement/m-p/48074#M12967</guid>
      <dc:creator>gxu</dc:creator>
      <dc:date>2011-08-15T17:38:20Z</dc:date>
    </item>
  </channel>
</rss>

