<?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: Coding new ordinal variable from many non-mutually exclusive binary variables in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Coding-new-ordinal-variable-from-many-non-mutually-exclusive/m-p/906243#M44986</link>
    <description>&lt;P&gt;You already have that with the existing variables.&amp;nbsp; Just include them all in the model.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Dec 2023 14:47:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-12-05T14:47:33Z</dc:date>
    <item>
      <title>Coding new ordinal variable from many non-mutually exclusive binary variables</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Coding-new-ordinal-variable-from-many-non-mutually-exclusive/m-p/906155#M44974</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a new ordinal variable from a set of responses to other non-mutually exclusive binary variables. I believe I am running into trouble with some of my commands overwriting others, resulting in my frequencies being incorrect for the new variable. Can anyone help me correct the code below, or suggest a better methods for creating this variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have tried coding many iterations but basically they come down to two main ways:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#1&lt;/P&gt;&lt;P&gt;data=dataset1&lt;/P&gt;&lt;P&gt;set dataset&lt;/P&gt;&lt;P&gt;anymental=.;&lt;/P&gt;&lt;P&gt;if anxiety=0 then anymental=0;&lt;/P&gt;&lt;P&gt;if mood=0 then anymental=0;&lt;/P&gt;&lt;P&gt;if eating=0 then anymental=0;&lt;/P&gt;&lt;P&gt;if anxiety=1 then anymental=1;&lt;/P&gt;&lt;P&gt;if mood=1 then anymental=2;&lt;/P&gt;&lt;P&gt;if eating=1 then anymental=3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#2&lt;/P&gt;&lt;P&gt;data=dataset1&lt;/P&gt;&lt;P&gt;set dataset&lt;/P&gt;&lt;P&gt;anymental=.;&lt;/P&gt;&lt;P&gt;if anxiety=0 then anymental=0;&lt;/P&gt;&lt;P&gt;if anxiety=1 then anymental=1;&lt;/P&gt;&lt;P&gt;if mood=0 then anymental=0;&lt;/P&gt;&lt;P&gt;if mood=1 then anymental=2;&lt;/P&gt;&lt;P&gt;if eating=0 then anymental=0;&lt;/P&gt;&lt;P&gt;if eating=1 then anymental=3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Neither is giving me the correct frequencies that I'd like to see for the anymental variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 00:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Coding-new-ordinal-variable-from-many-non-mutually-exclusive/m-p/906155#M44974</guid>
      <dc:creator>alexluther19</dc:creator>
      <dc:date>2023-12-05T00:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Coding new ordinal variable from many non-mutually exclusive binary variables</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Coding-new-ordinal-variable-from-many-non-mutually-exclusive/m-p/906162#M44975</link>
      <description>&lt;P&gt;You have two problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One is at the planning phase:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have 3 input binary variables (anxiety, mood , eating) you have 8 possible combinations.&lt;/P&gt;
&lt;P&gt;You seem to be trying to map those into just 4 different values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One is at the execution phase:&lt;/P&gt;
&lt;P&gt;Your logic is independent.&amp;nbsp; So if EATING=1 then it does not matter what values the other two variables has because that last IF/THEN will set the value to 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make yourself a truth table.&amp;nbsp; For every possible combination of the three variables what do you want for the output variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what your current code does:&lt;/P&gt;
&lt;PRE&gt;Obs    anxiety    mood    eating    anymental

 1        0         0        0          0
 2        0         0        1          3
 3        0         1        0          2
 4        0         1        1          3
 5        1         0        0          1
 6        1         0        1          3
 7        1         1        0          2
 8        1         1        1          3
&lt;/PRE&gt;
&lt;P&gt;So what did you want to do?&amp;nbsp; Did you just want to COUNT them?&amp;nbsp; Is so the add them up.&amp;nbsp; You could use the SUM() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  anymental=sum(anxiety,mood,eating);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    anxiety    mood    eating    anymental

 1        0         0        0          0
 2        0         0        1          1
 3        0         1        0          1
 4        0         1        1          2
 5        1         0        0          1
 6        1         0        1          2
 7        1         1        0          2
 8        1         1        1          3
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 01:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Coding-new-ordinal-variable-from-many-non-mutually-exclusive/m-p/906162#M44975</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-05T01:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Coding new ordinal variable from many non-mutually exclusive binary variables</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Coding-new-ordinal-variable-from-many-non-mutually-exclusive/m-p/906166#M44976</link>
      <description>&lt;P&gt;Thanks for your reply, its super helpful to conceptualize the issue through a truth table!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering now if what I'm looking to do is not possible, because I want the output variable to count some observations twice. For example, I want anymental for obs 4 to reflect both the mood (2) and the eating (3) values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I approaching this wrong in terms of what I want from anymental? The reason for creating anymental as an ordinal variable is to then be able to perform regression analyses to compare associations between the various health conditions contained within anymental and various sociodemographic factors.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 02:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Coding-new-ordinal-variable-from-many-non-mutually-exclusive/m-p/906166#M44976</guid>
      <dc:creator>alexluther19</dc:creator>
      <dc:date>2023-12-05T02:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Coding new ordinal variable from many non-mutually exclusive binary variables</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Coding-new-ordinal-variable-from-many-non-mutually-exclusive/m-p/906243#M44986</link>
      <description>&lt;P&gt;You already have that with the existing variables.&amp;nbsp; Just include them all in the model.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 14:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Coding-new-ordinal-variable-from-many-non-mutually-exclusive/m-p/906243#M44986</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-05T14:47:33Z</dc:date>
    </item>
  </channel>
</rss>

