<?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: How to create a new categorical variable from two other categorical variables. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/730073#M28390</link>
    <description>&lt;P&gt;Here is a sample data set and solution. It works for me. Try it out:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data run1;
input subject treatment diagnosis;
datalines;
1 0 1
2 1 0
3 0 0
4 0 1
5 1 0
6 1 1
7 0 1
8 1 0
9 0 0
;

data newrun1;
set run1;
if      treatment=0 and diagnosis=0 then group8=1;
else if treatment=0 and diagnosis=1 then group8=2;
else if treatment=1 and diagnosis=0 then group8=3;
else if treatment=1 and diagnosis=1 then group8=4;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most likely, the problem is your data. Either your input data set doesn't have the variables Treatment and Diagnosis (check your spelling!) or those variables do not have the values you think they do. Use the following to examine the values of your variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=run1;
tables treatment * diagnosis / norow nocol nopercent;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 30 Mar 2021 12:50:35 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2021-03-30T12:50:35Z</dc:date>
    <item>
      <title>How to create a new categorical variable from two other categorical variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728328#M28270</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some data and want to create a new variable from my current variables. I basically want the following outcome:&lt;/P&gt;&lt;P&gt;IF var1 = 0 and var2 = 0 then newvariable = 1&lt;/P&gt;&lt;P&gt;If var1 =0 and var2 = 1 then newvariable=2&lt;/P&gt;&lt;P&gt;If var1 = 1 and var2=0 then newvariable = 3&lt;/P&gt;&lt;P&gt;if var1 = 1 and var2=1 then newvariable = 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the following and it has not worked&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data new;&lt;/P&gt;&lt;P&gt;set old;&lt;/P&gt;&lt;P&gt;IF&amp;nbsp;var1 = 0 and var2 = 0 then newvariable = 1;&lt;/P&gt;&lt;P&gt;else If var1 =0 and var2 = 1 then newvariable=2;&lt;/P&gt;&lt;P&gt;else If var1 = 1 and var2=0 then newvariable = 3;&lt;/P&gt;&lt;P&gt;else if var1 = 1 and var2=1 then newvariable = 4;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 01:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728328#M28270</guid>
      <dc:creator>Rose1</dc:creator>
      <dc:date>2021-03-23T01:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new categorical variable from two other categorical variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728329#M28271</link>
      <description>&lt;P&gt;What is the input?&lt;BR /&gt;What is the output?&lt;/P&gt;
&lt;P&gt;Your if statements look ok.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;FYI all you need is a single assignment instead of 4 ifs:&lt;/P&gt;
&lt;P&gt;newvariable = 2 * var1 + var2 + 1;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 01:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728329#M28271</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2021-03-23T01:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new categorical variable from two other categorical variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728333#M28272</link>
      <description>&lt;P&gt;I've attached an example of my input (i've tried with and without parentheses)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56286iA3D2D050BF88EA70/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;When I print the new variable "group8", I would expect to see it coded 1,2,3 or 4 for each subject, but it is just blank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56285iA2AC256674B18104/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the end of this I basically want a new variable "group8" coded so I have 4 levels based on those original variables:&lt;/P&gt;&lt;P&gt;treatment 1 + diagnosis 1 = 1&lt;/P&gt;&lt;P&gt;treatment 2 + diagnosis 1 = 2&lt;/P&gt;&lt;P&gt;treatment 1 + diagnosis 2 = 3&lt;/P&gt;&lt;P&gt;treatment 2 + diagnosis 2 = 4&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this makes sense. Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 01:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728333#M28272</guid>
      <dc:creator>Rose1</dc:creator>
      <dc:date>2021-03-23T01:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new categorical variable from two other categorical variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728334#M28273</link>
      <description>&lt;P&gt;What is the input? Is group8 a character variable in the input data set? You need to provide more info.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 01:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728334#M28273</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2021-03-23T01:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new categorical variable from two other categorical variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728346#M28276</link>
      <description>&lt;P&gt;No, group8 is an arbitrary variable name I am trying to create based on these diagnosis and treatment variables. It does not exist in the input data set.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The input for the other variables is something like this -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-03-22 at 9.48.30 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56290iAD4823CB13673E03/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2021-03-22 at 9.48.30 PM.png" alt="Screen Shot 2021-03-22 at 9.48.30 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;What I want is SAS to code my data based on these variables so it puts out something like this:&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-03-22 at 9.48.34 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56291i5251FE60E4F2D61D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2021-03-22 at 9.48.34 PM.png" alt="Screen Shot 2021-03-22 at 9.48.34 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 03:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728346#M28276</guid>
      <dc:creator>Rose1</dc:creator>
      <dc:date>2021-03-23T03:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new categorical variable from two other categorical variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728347#M28277</link>
      <description>&lt;P&gt;No one is going to be able to help you if you show "input something like this." Show the actual input. Show the actual output. Show the actual code. If the data set is too big or proprietary, make up a small sample proof of concept data set. Showing proc contents results for the input would help too. Show the SAS log. Are there notes, errors, or warnings? Solving problems like this is simple only if you examine all the information.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 03:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728347#M28277</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2021-03-23T03:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new categorical variable from two other categorical variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728352#M28278</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/368843"&gt;@Rose1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;When I print the new variable "group8", I would expect to see it coded 1,2,3 or 4 for each subject, but it is just blank&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Check the log! Are there any unexpected notes, warnings?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 06:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/728352#M28278</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-03-23T06:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new categorical variable from two other categorical variables.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/730073#M28390</link>
      <description>&lt;P&gt;Here is a sample data set and solution. It works for me. Try it out:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data run1;
input subject treatment diagnosis;
datalines;
1 0 1
2 1 0
3 0 0
4 0 1
5 1 0
6 1 1
7 0 1
8 1 0
9 0 0
;

data newrun1;
set run1;
if      treatment=0 and diagnosis=0 then group8=1;
else if treatment=0 and diagnosis=1 then group8=2;
else if treatment=1 and diagnosis=0 then group8=3;
else if treatment=1 and diagnosis=1 then group8=4;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most likely, the problem is your data. Either your input data set doesn't have the variables Treatment and Diagnosis (check your spelling!) or those variables do not have the values you think they do. Use the following to examine the values of your variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=run1;
tables treatment * diagnosis / norow nocol nopercent;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Mar 2021 12:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-a-new-categorical-variable-from-two-other/m-p/730073#M28390</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-03-30T12:50:35Z</dc:date>
    </item>
  </channel>
</rss>

