<?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: Using output to statement to output different values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805327#M317224</link>
    <description>&lt;P&gt;Do you want the new dataset to have three versions of the observations that had a missing value for SEX?&amp;nbsp; That is what you coded.&amp;nbsp; Or did you want two observations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you want to use only one IF statement.&lt;/P&gt;
&lt;P&gt;So if you want three observations do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;output;
if sex=" " and age ne . then do;
  sex="M";
  output;
  sex="F";
  output;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only want two observations for those records then do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if sex=" " and age ne . then do;
  sex="M";
  output;
  sex="F";
  output;
end;
else output;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 31 Mar 2022 15:11:26 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-03-31T15:11:26Z</dc:date>
    <item>
      <title>Using output to statement to output different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805325#M317222</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;The dataset I have is :&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data subj0;&lt;BR /&gt;input subj $4. sex $2. age;&lt;BR /&gt;datalines;&lt;BR /&gt;101 M 23&lt;BR /&gt;102 F 25&lt;BR /&gt;103 F 28&lt;BR /&gt;104&amp;nbsp; &amp;nbsp; 23&lt;BR /&gt;105 F 24&lt;BR /&gt;106 M .&lt;BR /&gt;107 F 28&lt;BR /&gt;108&amp;nbsp; &amp;nbsp; 22&lt;BR /&gt;109 F 25&lt;BR /&gt;110 F .&lt;BR /&gt;111&amp;nbsp; &amp;nbsp; .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some subjects have missing sex but age is available, for those subjects I am trying to populate them as both 'M' and 'F' as separate records. I have tried using the below output statement but unsure where I am going wrong as it stops at second output statement. For the third output statement to work, the condition is still met (ie. missing sex and age is present) but it is not running.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data exp;&lt;BR /&gt;set subj0;&lt;BR /&gt;output;&lt;BR /&gt;if sex=" " and age ne . then do;&lt;BR /&gt;sex="M";&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;if sex=" " and age ne . then do;&lt;BR /&gt;sex="F";&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 15:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805325#M317222</guid>
      <dc:creator>Tommer</dc:creator>
      <dc:date>2022-03-31T15:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using output to statement to output different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805327#M317224</link>
      <description>&lt;P&gt;Do you want the new dataset to have three versions of the observations that had a missing value for SEX?&amp;nbsp; That is what you coded.&amp;nbsp; Or did you want two observations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you want to use only one IF statement.&lt;/P&gt;
&lt;P&gt;So if you want three observations do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;output;
if sex=" " and age ne . then do;
  sex="M";
  output;
  sex="F";
  output;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only want two observations for those records then do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if sex=" " and age ne . then do;
  sex="M";
  output;
  sex="F";
  output;
end;
else output;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2022 15:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805327#M317224</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-31T15:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using output to statement to output different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805334#M317228</link>
      <description>Thank  you so much Tom! Any idea what I was doing incorrectly? My understanding is using 'end' just closes the do block. When I have the next Do block, I thought it would run normally as a separate Do block and output, which was not. If you have a minute would you mind helping me understand?</description>
      <pubDate>Thu, 31 Mar 2022 15:25:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805334#M317228</guid>
      <dc:creator>Tommer</dc:creator>
      <dc:date>2022-03-31T15:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using output to statement to output different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805342#M317233</link>
      <description>&lt;P&gt;The statements were perfectly valid.&lt;/P&gt;
&lt;P&gt;Your LOGIC was flawed.&lt;/P&gt;
&lt;P&gt;The first IF block executed and changed SEX to 'M'.&lt;/P&gt;
&lt;P&gt;So the second IF block never executed.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 15:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805342#M317233</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-31T15:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using output to statement to output different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805351#M317239</link>
      <description>My logic was after the first two output statements in my code, there are still rows with missing sex and not missing age (the second do block converted missing to "M" but from the first Do block we have missing sex) which will be the input for the third Do block.</description>
      <pubDate>Thu, 31 Mar 2022 16:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805351#M317239</guid>
      <dc:creator>Tommer</dc:creator>
      <dc:date>2022-03-31T16:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using output to statement to output different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805354#M317240</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/284458"&gt;@Tommer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;My logic was after the first two output statements in my code, there are still rows with missing sex and not missing age (the second do block converted missing to "M" but from the first Do block we have missing sex) which will be the input for the third Do block.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I cannot figure out what you are saying.&lt;/P&gt;
&lt;P&gt;Try it with a manipulative.&amp;nbsp; Use a piece of paper to represent the variable SEX for one observation read by the SET statement.&amp;nbsp; It will start as blank.&amp;nbsp; Now write the letter M on it.&amp;nbsp; Now read it.&amp;nbsp; What does it say? Is it still blank?&amp;nbsp; Or does it have the letter M on it?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 16:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805354#M317240</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-31T16:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using output to statement to output different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805374#M317251</link>
      <description>My thought process for how 'output' works was way off. Played around a bit to understand better, thanks Tom.</description>
      <pubDate>Thu, 31 Mar 2022 18:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-output-to-statement-to-output-different-values/m-p/805374#M317251</guid>
      <dc:creator>Tommer</dc:creator>
      <dc:date>2022-03-31T18:09:21Z</dc:date>
    </item>
  </channel>
</rss>

