<?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: when I add the a row of code----output , the result change, why ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/when-I-add-the-a-row-of-code-output-the-result-change-why/m-p/737774#M230035</link>
    <description>&lt;P&gt;In both DATA steps, the final value of MONTH is 13.&amp;nbsp; Inside the loop it goes from 1 to 12.&amp;nbsp; At the END statement for the 12th time, SAS increases the value to 13 and then notices that the loop is over.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When the DATA step contains an OUTPUT statement, the only time an observation gets output is when the OUTPUT statement executes.&amp;nbsp; So with no OUTPUT statement, the observation gets output at the end of all the programming logic when MONTH is 13.&amp;nbsp; Once the OUTPUT statement is added, the outputting occurs inside the loop, before reaching the end of the logic, and before increasing MONTH to 13.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Apr 2021 00:40:07 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2021-04-29T00:40:07Z</dc:date>
    <item>
      <title>when I add the a row of code----output , the result change, why ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/when-I-add-the-a-row-of-code-output-the-result-change-why/m-p/737772#M230034</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.sale2;
 do Month = 1 to 12;
	    X + 1;
     end;
	 
run;
proc print data = work.sale2;
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_1-1619655246486.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58841iAE821FED51DF9C20/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tianerhu_1-1619655246486.png" alt="tianerhu_1-1619655246486.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;* the value of month is 12 ;&lt;/P&gt;
&lt;P&gt;data work.sale2;&lt;BR /&gt;do Month = 1 to 12;&lt;BR /&gt;X + 1;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;proc print data = work.sale2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tianerhu_2-1619655285430.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58842i9AC026B1B6FC49E9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tianerhu_2-1619655285430.png" alt="tianerhu_2-1619655285430.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* the value of month is 13&lt;/P&gt;
&lt;P&gt;the value of month in the the two sas data set is different, Why ?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 00:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/when-I-add-the-a-row-of-code-output-the-result-change-why/m-p/737772#M230034</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-04-29T00:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: when I add the a row of code----output , the result change, why ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/when-I-add-the-a-row-of-code-output-the-result-change-why/m-p/737774#M230035</link>
      <description>&lt;P&gt;In both DATA steps, the final value of MONTH is 13.&amp;nbsp; Inside the loop it goes from 1 to 12.&amp;nbsp; At the END statement for the 12th time, SAS increases the value to 13 and then notices that the loop is over.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When the DATA step contains an OUTPUT statement, the only time an observation gets output is when the OUTPUT statement executes.&amp;nbsp; So with no OUTPUT statement, the observation gets output at the end of all the programming logic when MONTH is 13.&amp;nbsp; Once the OUTPUT statement is added, the outputting occurs inside the loop, before reaching the end of the logic, and before increasing MONTH to 13.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 00:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/when-I-add-the-a-row-of-code-output-the-result-change-why/m-p/737774#M230035</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-04-29T00:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: when I add the a row of code----output , the result change, why ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/when-I-add-the-a-row-of-code-output-the-result-change-why/m-p/737775#M230036</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268447"&gt;@tianerhu&lt;/a&gt;&amp;nbsp; Please run the below, check the LOG and you tell us why&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data work.sale2;
do Month = 1 to 12;
X + 1;
put month=;
end;
put month=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Apr 2021 00:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/when-I-add-the-a-row-of-code-output-the-result-change-why/m-p/737775#M230036</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-04-29T00:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: when I add the a row of code----output , the result change, why ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/when-I-add-the-a-row-of-code-output-the-result-change-why/m-p/737778#M230038</link>
      <description>&lt;P&gt;When you do not have an Output statement the SAS data step uses an implied "output" at the bottom or end of the step.&lt;/P&gt;
&lt;P&gt;If you only have on "end" of the data step you only get one record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your layout of your question is confusing:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data work.sale2;
 do Month = 1 to 12;
	    X + 1;
     end;
	 
run;&lt;/LI-CODE&gt;
&lt;P&gt;will only generate one output record. (the second output example).&lt;/P&gt;
&lt;P&gt;Your Second data step&lt;/P&gt;
&lt;PRE&gt;data work.sale2;
do Month = 1 to 12;
X + 1;
output;
end;&lt;/PRE&gt;
&lt;P&gt;will generate 12 records (the First proc print result you show).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Output statement is executable when means when one is encountered in the code the current data is written to the output. When you add any explicit output statement then you have told SAS that you are controlling when/where the output data is to go.&lt;/P&gt;
&lt;P&gt;You can have multiple output statements in a single data step to create additional records. You can have output statements to specify which data set to write to when.&lt;/P&gt;
&lt;P&gt;Consider this code. See the values&lt;/P&gt;
&lt;PRE&gt;Data example;
   do i=1 to 3;
       output;&lt;BR /&gt;       x=2+i;
       output;&lt;BR /&gt;       y=3+i;
       output;&lt;BR /&gt;       z=4+i;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;Work out the results. When you figure out why any particular value is in the output you'll have learned an important lesson.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 00:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/when-I-add-the-a-row-of-code-output-the-result-change-why/m-p/737778#M230038</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-29T00:47:09Z</dc:date>
    </item>
  </channel>
</rss>

