<?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: output statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285666#M58452</link>
    <description>&lt;P&gt;@ Astounding, Thanks for clarification. &amp;nbsp;So only that observation is outputted (output statment) even there are other observations in the input data set, right? &amp;nbsp;In my example the input data set has 2 observations, but only one observation meets the criteria in the output statement.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
	set SASHELP.CLASS (WHERE= (NAME in ("Alfred","Alice")));

	if Name = "Alfred" then
		output;

/* 	if Name = "Alice" then */
/* 		output; */
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jul 2016 23:02:51 GMT</pubDate>
    <dc:creator>SAS_inquisitive</dc:creator>
    <dc:date>2016-07-19T23:02:51Z</dc:date>
    <item>
      <title>output statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285630#M58439</link>
      <description>&lt;P&gt;Why does the second &amp;nbsp;program (want2) create missing flag variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
	set SASHELP.CLASS (WHERE= (NAME in ("Alfred","Alice")));

	if Sex ='M' then
		Flag = 1;

	if Name = "Alfred" then
		output;

	if Name = "Alice" then
		output;
run;

data want2;
	set SASHELP.CLASS (WHERE= (NAME in ("Alfred","Alice")));

	if Name = "Alfred" then
		output;

	if Name = "Alice" then
		output;

	if Sex ='M' then
		Flag = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 20:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285630#M58439</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-07-19T20:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: output statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285636#M58445</link>
      <description>&lt;P&gt;There are two factors at work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, the statements in the DATA step execute in order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, the OUTPUT statement does not mean output at the end of the DATA step.&amp;nbsp; It means output right now, before doing any more work.&amp;nbsp; So the OUTPUT statement executes before assigning a value to FLAG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FLAG is still part of the output because SAS has already looked through your statements to see what variables it needs to create.&amp;nbsp; But it has a missing value because it is output before the final IF/THEN statement executes.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 20:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285636#M58445</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-19T20:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: output statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285666#M58452</link>
      <description>&lt;P&gt;@ Astounding, Thanks for clarification. &amp;nbsp;So only that observation is outputted (output statment) even there are other observations in the input data set, right? &amp;nbsp;In my example the input data set has 2 observations, but only one observation meets the criteria in the output statement.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
	set SASHELP.CLASS (WHERE= (NAME in ("Alfred","Alice")));

	if Name = "Alfred" then
		output;

/* 	if Name = "Alice" then */
/* 		output; */
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 23:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285666#M58452</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-07-19T23:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: output statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285682#M58462</link>
      <description>&lt;P&gt;That's not the correct way of thinking about it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS loops through each row. So first iteration, first IF condition is met so the record is output. On second iteration, Second IF condition is met so the record is output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set sashelp.class ;&lt;/P&gt;
&lt;P&gt;where name in ('Alice' 'Alfred');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if name='Alice' then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if sex='F' then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if name='Alfred' then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 23:58:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285682#M58462</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-19T23:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: output statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285708#M58470</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;. Thanks. This is helpful.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 01:56:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285708#M58470</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-07-20T01:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: output statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285710#M58471</link>
      <description>&lt;P&gt;I'm not sure if this helps or not, but there is one additional implication of the OUTPUT statement. &amp;nbsp;When a DATA step contains an OUTPUT statement, the only time an observation gets output is when the OUTPUT statement executes.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 02:14:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285710#M58471</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-20T02:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: output statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285844#M58520</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;. &amp;nbsp;Thanks. This is what I was assuming.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 15:06:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-statement/m-p/285844#M58520</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-07-20T15:06:29Z</dc:date>
    </item>
  </channel>
</rss>

