<?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: Creating a variable from other variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852697#M337044</link>
    <description>&lt;P&gt;Do you really have character variables now as the code is showing or numeric variables as your problem statement is showing?&amp;nbsp; &amp;nbsp; If you do have character variables why are you making the new variable numeric instead of character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not just code the statement as you have written it?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if COPD=1 or EMPHY=1 or BRONCH=1 then COPDix=1;
else if COPD=. or EMPHY=. or BRONCH=. then COPDix=.;
else COPDix=0;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 08 Jan 2023 14:50:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-01-08T14:50:08Z</dc:date>
    <item>
      <title>Creating a variable from other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852695#M337042</link>
      <description>&lt;P&gt;Hello programmers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 3 variables (COPD, EMPHY and BRONCH) with values 0,1 and . (missing) that i want to use to make a new variable COPDix with 0,1 and .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want if COPD=1 or EMPHY=1 or BRONCH=1 then COPDix=1;&lt;/P&gt;&lt;P&gt;and if COPD=. or EMPHY=. or BRONCH=. then COPDix=.;&lt;/P&gt;&lt;P&gt;every other thing should be zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Data ACBS2; set ACBS1;
if COPD= '.' then COPDix=.;
if Bronch= '.' then COPDix=.;
if Emphy= '.' then COPDix=.;
if COPD= '1' then COPDix=1;
else if Bronch= '1' then COPDix=1;
else if Emphy= '1' then COPDix=1;
else COPDix=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This code implements only COPD=1 or EMPHY=1 or Bronch=1 then COPDix=1;&lt;/P&gt;&lt;P&gt;However it doesn't implement the second idea: It calls both . and 0 in COPD, EMPHY and BRONCH as 0 in COPDix.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know i'm missing a little bit of something to make this work. Any help will be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2023 14:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852695#M337042</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2023-01-08T14:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852696#M337043</link>
      <description>sorry i meant:&lt;BR /&gt;&lt;BR /&gt;I want if COPD=1 or EMPHY=1 or BRONCH=1 then COPDix=1;&lt;BR /&gt;&lt;BR /&gt;and if COPD=. AND EMPHY=. AND BRONCH=. then COPDix=.;</description>
      <pubDate>Sun, 08 Jan 2023 14:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852696#M337043</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2023-01-08T14:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852697#M337044</link>
      <description>&lt;P&gt;Do you really have character variables now as the code is showing or numeric variables as your problem statement is showing?&amp;nbsp; &amp;nbsp; If you do have character variables why are you making the new variable numeric instead of character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not just code the statement as you have written it?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if COPD=1 or EMPHY=1 or BRONCH=1 then COPDix=1;
else if COPD=. or EMPHY=. or BRONCH=. then COPDix=.;
else COPDix=0;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2023 14:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852697#M337044</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-08T14:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852698#M337045</link>
      <description>&lt;P&gt;If you are unclear what result you want it might help to build a truth table.&lt;/P&gt;
&lt;P&gt;Show for all combinations of the possible values of the three input values what output you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you appear to be using tri-level logic instead of binary logic there will by 3*3*3 = 27 possible combination of the three input variables.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2023 14:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852698#M337045</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-08T14:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852699#M337046</link>
      <description>Hi Tom,&lt;BR /&gt;The second case is&lt;BR /&gt;if COPD=. AND EMPHY=. AND BRONCH=. then COPDix=.;</description>
      <pubDate>Sun, 08 Jan 2023 14:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852699#M337046</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2023-01-08T14:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852700#M337047</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236266"&gt;@ChuksManuel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Tom,&lt;BR /&gt;The second case is&lt;BR /&gt;if COPD=. AND EMPHY=. AND BRONCH=. then COPDix=.;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So just change it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does it work or not?&lt;/P&gt;
&lt;P&gt;If not show an example set of inputs that it is not producing the right answer for.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2023 14:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852700#M337047</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-08T14:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852701#M337048</link>
      <description>&lt;P&gt;I suspect you just want to use the MAX() function.&lt;/P&gt;
&lt;P&gt;Let's do a truth table for two inputs and show the result of the MAX() function and you can compare that to what you want.&amp;nbsp; It should then work the same for 3 or more variables.&lt;/P&gt;
&lt;P&gt;Here are all 9 (3*3) possible combinations.&lt;/P&gt;
&lt;PRE&gt;A  B MAX(A,B)
0  0  0
0  1  1
1  0  1
1  1  1
.  .  .
.  0  0
.  1  1
0  .  0
1  .  1 &lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Jan 2023 15:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-other-variables/m-p/852701#M337048</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-08T15:03:54Z</dc:date>
    </item>
  </channel>
</rss>

