<?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: why the number of year and month is added 1 when remove the 'output'? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742115#M232067</link>
    <description>&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
    <pubDate>Tue, 18 May 2021 12:44:37 GMT</pubDate>
    <dc:creator>tianerhu</dc:creator>
    <dc:date>2021-05-18T12:44:37Z</dc:date>
    <item>
      <title>why the number of year and month is added 1 when remove the 'output'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742045#M232037</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname results 'C:\practice everyday\output';
data results.output13_2;
total = 100;
do year = 1 to 3;
  do month = 1 to 12;
   total + total*0.05;
 output;
 end;
 total + 50;
end;
run;
proc print data = results.output13_2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tianerhu_0-1621304576456.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59531iAEC6F5A21D71AE7B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tianerhu_0-1621304576456.png" alt="tianerhu_0-1621304576456.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;libname results 'C:\practice everyday\output';&lt;BR /&gt;data results.output13_2;&lt;BR /&gt;total = 100;&lt;BR /&gt;do year = 1 to 3;&lt;BR /&gt;do month = 1 to 12;&lt;BR /&gt;total + total*0.05;&lt;BR /&gt;*output;&lt;BR /&gt;end;&lt;BR /&gt;total + 50;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;proc print data = results.output13_2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tianerhu_1-1621304604122.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59532i0A25B0CB4BD340F4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tianerhu_1-1621304604122.png" alt="tianerhu_1-1621304604122.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 02:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742045#M232037</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-18T02:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: why the number of year and month is added 1 when remove the 'output'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742048#M232038</link>
      <description>&lt;P&gt;In your first program you have an explicit OUTPUT statement inside the DO loop.&amp;nbsp; Therefore the normal implicit OUTPUT (just before the RUN; statement) is eliminated.&amp;nbsp; But in your second program, there is no explicit OUTPUT, so the implicit OUTPUT is executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the question really is "why does the iterator YEAR in &lt;EM&gt;&lt;STRONG&gt;DO YEAR=1 to 3; ... END;&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;end up as a 4"?&amp;nbsp; &amp;nbsp;The iterator is always incremented (from 1 to 2, 2 to 3, 3 to 4) &lt;EM&gt;&lt;STRONG&gt;at the end of each iteration.&lt;/STRONG&gt;&lt;/EM&gt;.&amp;nbsp; Once YEAR=4 there is no subsequent iteration of the DO loop executed, because it is now outside of the upper limit of 3.&amp;nbsp; Here's code to show that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do year=1 to 3 ;
    put 'inside ' year=;
  end;
  put 'after  ' year=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, if you really want to iterate from year=1 to 3 without year being incremented to 4 you can add an UNTIL expression:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do year=1 to 3 until (year=3);
    put 'inside ' year=;
  end;
  put 'after  ' year=;
run;    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works because the UNTIL expression (telling the loop when to stop) is evaluated at the end of each iteration, but before the iterator is incremented.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 03:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742048#M232038</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-05-18T03:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: why the number of year and month is added 1 when remove the 'output'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742105#M232059</link>
      <description>&lt;P&gt;Thank you so much .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 11:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742105#M232059</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-18T11:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: why the number of year and month is added 1 when remove the 'output'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742107#M232061</link>
      <description>&lt;P&gt;Could you explain why the variable month become 13, the same way to the variable year ?&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 11:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742107#M232061</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-18T11:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: why the number of year and month is added 1 when remove the 'output'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742108#M232062</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268447"&gt;@tianerhu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Could you explain why the variable month become 13, the same way to the variable year ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's the same reason as year; the loop increments month to 13, then it stops as the loop will not run when month is 13.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 11:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742108#M232062</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-05-18T11:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: why the number of year and month is added 1 when remove the 'output'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742115#M232067</link>
      <description>&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 12:44:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-the-number-of-year-and-month-is-added-1-when-remove-the/m-p/742115#M232067</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-18T12:44:37Z</dc:date>
    </item>
  </channel>
</rss>

