<?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: Assistance with Recoding 5 variables into 1 new variable - New User in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816719#M34349</link>
    <description>&lt;P&gt;You need ELSE before the last 4 IF statements.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jun 2022 19:09:16 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-06-06T19:09:16Z</dc:date>
    <item>
      <title>Assistance with Recoding 5 variables into 1 new variable - New User</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816718#M34348</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a new user to SAS and I am really struggling with some very basic commands. I have a dataset where I have 5 variables of race (e.g., asian, black, white, pacific etc.) and teach row represents a subject with an 'X' marking the category they fall into.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS_Novice22_1-1654542282342.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72024i4A468F2FCD32B24D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAS_Novice22_1-1654542282342.png" alt="SAS_Novice22_1-1654542282342.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I would like to create a single new variable titled 'race' (which I have successfully done - yay me) and then re-categorize the 5 race variables into my new variable accordingly. Anything missing entries would be coded as ".".&lt;/P&gt;&lt;P&gt;Here is a copy of my code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS_Novice22_0-1654542117531.png" style="width: 215px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72023i0933C647A8A1C54E/image-dimensions/215x187?v=v2" width="215" height="187" role="button" title="SAS_Novice22_0-1654542117531.png" alt="SAS_Novice22_0-1654542117531.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am not getting any error messages per se but it is not recoding from the original variables to the new variable the way I am intending.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS_Novice22_2-1654542323517.png" style="width: 70px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72025iD7034730660ECDB2/image-dimensions/70x78?v=v2" width="70" height="78" role="button" title="SAS_Novice22_2-1654542323517.png" alt="SAS_Novice22_2-1654542323517.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any feedback would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;BR /&gt;T.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816718#M34348</guid>
      <dc:creator>SAS_Novice22</dc:creator>
      <dc:date>2022-06-06T19:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with Recoding 5 variables into 1 new variable - New User</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816719#M34349</link>
      <description>&lt;P&gt;You need ELSE before the last 4 IF statements.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816719#M34349</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-06T19:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with Recoding 5 variables into 1 new variable - New User</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816720#M34350</link>
      <description>&lt;P&gt;You have 4 IF statements and then an IF/ELSE statement. The ELSE in that last statement overwrites any of your first 4 IFs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should have ELSE IF instead of IF in the 2nd-4th series of statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post your code as text, makes it much easier to correct any mistakes without having to re-type out all the code.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:17:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816720#M34350</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-06T19:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with Recoding 5 variables into 1 new variable - New User</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816723#M34351</link>
      <description>Hi Paige,&lt;BR /&gt;Amazing, thank you, that worked.&lt;BR /&gt;Have a great day.&lt;BR /&gt;T.&lt;BR /&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816723#M34351</guid>
      <dc:creator>SAS_Novice22</dc:creator>
      <dc:date>2022-06-06T19:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with Recoding 5 variables into 1 new variable - New User</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816725#M34352</link>
      <description>&lt;P&gt;In your code, whenevr &lt;STRONG&gt;other&amp;nbsp; ne 'x'&lt;/STRONG&gt; you will get &lt;STRONG&gt;race = .;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;You should add&amp;nbsp;&lt;STRONG&gt;else&lt;/STRONG&gt; after each&amp;nbsp;&lt;STRONG&gt;if&lt;/STRONG&gt; statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
      if asian = 'X' then race = 1; else
      if balch = 'X' then race = 2; else
     ...
    if other = 'X' then race = 5; else race = .;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816725#M34352</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2022-06-06T19:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with Recoding 5 variables into 1 new variable - New User</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816726#M34353</link>
      <description>&lt;P&gt;Thank you very helpful. That fixed this issue. Also thank you for the posting pointers, that was my first post. I will know for next time&lt;BR /&gt;Thank you!&lt;BR /&gt;T.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816726#M34353</guid>
      <dc:creator>SAS_Novice22</dc:creator>
      <dc:date>2022-06-06T19:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with Recoding 5 variables into 1 new variable - New User</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816727#M34354</link>
      <description>&lt;P&gt;Or better you could add the else BEFORE the statements where humans are more likely to notice it and makes each line only contain one statement instead of one and half statements.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816727#M34354</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-06T19:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with Recoding 5 variables into 1 new variable - New User</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816769#M34370</link>
      <description>&lt;P&gt;Another way to examine multiple variables for the same value is the WHICHC function for Character values or WHICHN for Numeric values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note here is also a way to provide an example data set:&lt;/P&gt;
&lt;PRE&gt;data example;
   input (asian black pacific white other) ($);
datalines;
x . . . .
. x . . .
. . x . .
. . . x .
. . . . x
. . . . .
;

data want;
   set example;
   race = whichc('x',asian, black, pacific, white, other);
   if race = 0 then race=.;
run;
&lt;/PRE&gt;
&lt;P&gt;Whichc, or Whichn, return the position position number of the value if found or 0 otherwise. &lt;BR /&gt;Since your problem is related to the sequence of position this function does most of the work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Great big&lt;/STRONG&gt; caveat: Nothing in your code provides for multiple race codes selected and a very large number of data systems that collect race will allow multiple answers. If that is possible in your data you likely need to address that potential issue. Quite possibly with a bit more work depending on values and any other rules for your use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can test for that with code like:&lt;/P&gt;
&lt;PRE&gt;Proc freq data=demo;
   tables asian* black* pacific* white* other/ list missing;
run;&lt;/PRE&gt;
&lt;P&gt;If any of the output lines have more than one variable with an X you need to address that.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 21:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assistance-with-Recoding-5-variables-into-1-new-variable-New/m-p/816769#M34370</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-06T21:12:43Z</dc:date>
    </item>
  </channel>
</rss>

