<?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 Recode multiple categorial variables into one variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recode-multiple-categorial-variables-into-one-variable/m-p/488406#M287410</link>
    <description>&lt;P&gt;Hi...I'm teaching myself SAS and am new to this community board.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to recode 12 categorical variables (pbc_1-pbc_12) with the response "yes",&amp;nbsp;"no", and "unsure". In my code, "yes" = 2, "no" = 1, and "unsure" = 3.&amp;nbsp; I want to only capture the "yes" responses from the 12 variables and create one variable (precon).&amp;nbsp; I'm&amp;nbsp;using "else if" statements, but the code is not working.&amp;nbsp; I also don't know if I am accounting for the "no" and "unsure" responses correctly.&amp;nbsp; I essentially want to examine the distribution of "yes" responses.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;precon=.;&lt;BR /&gt;if pbc_1 = 2 then precon = 1;&amp;nbsp;&lt;BR /&gt;else if pbc_2= 2 then precon = 2;&amp;nbsp;&lt;BR /&gt;else if pbc_3= 2 then precon = 3;&amp;nbsp;&lt;BR /&gt;else if pbc_4 = 2 then precon = 4;&amp;nbsp;&lt;BR /&gt;else if pbc_5= 2 then precon = 5;&amp;nbsp;&lt;BR /&gt;else if pbc_6 = 2 then precon = 6;&amp;nbsp;&lt;BR /&gt;else if pbc_7 = 2 then precon = 7;&amp;nbsp;&lt;BR /&gt;else if pbc_8 = 2 then precon = 8;&amp;nbsp;&lt;BR /&gt;else if pbc_9 = 2 then precon = 9;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;else if pbc_10 = 2 then precon = 10;&amp;nbsp;&lt;BR /&gt;else if pbc_11 = 2 then precon = 11;&lt;BR /&gt;else if pbc_12= 2 then precon =&amp;nbsp;12;&lt;BR /&gt;else precon = .;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please help any way you can.&amp;nbsp; Also, if there is a more sophisticated&amp;nbsp;way of doing this type of procedure please let me know. Thanks! Trace&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Aug 2018 01:10:10 GMT</pubDate>
    <dc:creator>TraceC</dc:creator>
    <dc:date>2018-08-21T01:10:10Z</dc:date>
    <item>
      <title>Recode multiple categorial variables into one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-multiple-categorial-variables-into-one-variable/m-p/488406#M287410</link>
      <description>&lt;P&gt;Hi...I'm teaching myself SAS and am new to this community board.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to recode 12 categorical variables (pbc_1-pbc_12) with the response "yes",&amp;nbsp;"no", and "unsure". In my code, "yes" = 2, "no" = 1, and "unsure" = 3.&amp;nbsp; I want to only capture the "yes" responses from the 12 variables and create one variable (precon).&amp;nbsp; I'm&amp;nbsp;using "else if" statements, but the code is not working.&amp;nbsp; I also don't know if I am accounting for the "no" and "unsure" responses correctly.&amp;nbsp; I essentially want to examine the distribution of "yes" responses.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;precon=.;&lt;BR /&gt;if pbc_1 = 2 then precon = 1;&amp;nbsp;&lt;BR /&gt;else if pbc_2= 2 then precon = 2;&amp;nbsp;&lt;BR /&gt;else if pbc_3= 2 then precon = 3;&amp;nbsp;&lt;BR /&gt;else if pbc_4 = 2 then precon = 4;&amp;nbsp;&lt;BR /&gt;else if pbc_5= 2 then precon = 5;&amp;nbsp;&lt;BR /&gt;else if pbc_6 = 2 then precon = 6;&amp;nbsp;&lt;BR /&gt;else if pbc_7 = 2 then precon = 7;&amp;nbsp;&lt;BR /&gt;else if pbc_8 = 2 then precon = 8;&amp;nbsp;&lt;BR /&gt;else if pbc_9 = 2 then precon = 9;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;else if pbc_10 = 2 then precon = 10;&amp;nbsp;&lt;BR /&gt;else if pbc_11 = 2 then precon = 11;&lt;BR /&gt;else if pbc_12= 2 then precon =&amp;nbsp;12;&lt;BR /&gt;else precon = .;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please help any way you can.&amp;nbsp; Also, if there is a more sophisticated&amp;nbsp;way of doing this type of procedure please let me know. Thanks! Trace&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 01:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-multiple-categorial-variables-into-one-variable/m-p/488406#M287410</guid>
      <dc:creator>TraceC</dc:creator>
      <dc:date>2018-08-21T01:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Recode multiple categorial variables into one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-multiple-categorial-variables-into-one-variable/m-p/488414#M287411</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean by "not working"?&amp;nbsp; What does a sample of your data look like?&amp;nbsp; And what values would the resulting new variable&amp;nbsp;take for that sample?&amp;nbsp; Do you ever have more than one "yes" in the 12 variables?&amp;nbsp; If so, what rule will you use to make the new variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wanting to look at the "distribution of yes" responses suggests to me that, instead of finding a single summary variable, you may want to do cross-tabulations of the 12 original variables - this assumes that the "yes" values are not mutually exclusive.&amp;nbsp;&amp;nbsp; Or perhaps you can make 12&amp;nbsp;zero/one variables and generate a 12*12 correlation matrix from them?&amp;nbsp; I guess I'm asking what is it that you want to be able to say about these data?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 02:37:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-multiple-categorial-variables-into-one-variable/m-p/488414#M287411</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-08-21T02:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: Recode multiple categorial variables into one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-multiple-categorial-variables-into-one-variable/m-p/488537#M287412</link>
      <description>&lt;P&gt;Better post some sample data and result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here could give you a start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;array x{*} pbc_1-pbc_12;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;precon&amp;nbsp;= whichn(2,of x{*});&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 13:17:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-multiple-categorial-variables-into-one-variable/m-p/488537#M287412</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-21T13:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Recode multiple categorial variables into one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-multiple-categorial-variables-into-one-variable/m-p/488619#M287413</link>
      <description>&lt;P&gt;It is not clear if you want a separate result if you have only 1 variable with the value of 2 or multiple variables with the value of 2 or what to do with your 'no' or 'unsure' at all.&lt;/P&gt;
&lt;P&gt;The code you have written will stop testing and assign a value to precon for the first match. Was that your intent?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And distribution of "yes" responses is also kind of vague.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Not working" is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way to search for a single specific numeric&amp;nbsp;value from a group of variables. The order the variables appear in the array statement will affect results.&lt;/P&gt;
&lt;P&gt;If you don't like the result of 0 when no match then add code to assign the value you want. This also will count the number of yes responses for a record.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array pb pbc_1-pbc_12;
   precon = whichn(2,of pb(*);
   Numyes = countc('2',catx(' ',of pb(*));
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 15:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-multiple-categorial-variables-into-one-variable/m-p/488619#M287413</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-21T15:08:32Z</dc:date>
    </item>
  </channel>
</rss>

