<?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 how do you combine two variables into one variable in the same dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959867#M43112</link>
    <description>&lt;P&gt;I have been working on this code for three hours for a school assignment, can you please help? I have a large dataset where I need to combine the ethnicity and race and create a variable called group with the following values: 1 (black non-Hispanic) ,&amp;nbsp; 2 (white non-Hispanic), and 3 (Hispanic).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following is the "key"&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;"1"= "American Indian or Alaska Native"&lt;BR /&gt;               "2"= "Asian"&lt;BR /&gt;               "3"= "Black or African American"&lt;BR /&gt;               "4"= "Native Hawaiian or Other Pacific Islander"&lt;BR /&gt;               "5"= "White"&lt;BR /&gt;               "6"= "Other"&lt;BR /&gt;               "7"= "Unknown";&lt;/PRE&gt;&lt;PRE&gt;"E1"= "Hispanic or Latino"&lt;BR /&gt;                    "E2"= "Non-Hispanic or Latino"&lt;BR /&gt;                    "E7"= "Unknown";&lt;/PRE&gt;&lt;P&gt;I think I might be on to something here with this code but I think I need to make a variable named "group"&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*Create a new variable called group*/
DATA=APPENDICITIS.PROJECT3;
if ETHNICITY = "E2" AND RACE = "3" THEN GROUP = "1";
if ETHNICITY = "E2" AND RACE = "5" THEN GROUP = "2";
IF ETHNICITY = "E1" THEN GROUP = "3";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks so much for your expertise and time.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Feb 2025 00:34:25 GMT</pubDate>
    <dc:creator>whyamihere</dc:creator>
    <dc:date>2025-02-21T00:34:25Z</dc:date>
    <item>
      <title>how do you combine two variables into one variable in the same dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959867#M43112</link>
      <description>&lt;P&gt;I have been working on this code for three hours for a school assignment, can you please help? I have a large dataset where I need to combine the ethnicity and race and create a variable called group with the following values: 1 (black non-Hispanic) ,&amp;nbsp; 2 (white non-Hispanic), and 3 (Hispanic).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following is the "key"&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;"1"= "American Indian or Alaska Native"&lt;BR /&gt;               "2"= "Asian"&lt;BR /&gt;               "3"= "Black or African American"&lt;BR /&gt;               "4"= "Native Hawaiian or Other Pacific Islander"&lt;BR /&gt;               "5"= "White"&lt;BR /&gt;               "6"= "Other"&lt;BR /&gt;               "7"= "Unknown";&lt;/PRE&gt;&lt;PRE&gt;"E1"= "Hispanic or Latino"&lt;BR /&gt;                    "E2"= "Non-Hispanic or Latino"&lt;BR /&gt;                    "E7"= "Unknown";&lt;/PRE&gt;&lt;P&gt;I think I might be on to something here with this code but I think I need to make a variable named "group"&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*Create a new variable called group*/
DATA=APPENDICITIS.PROJECT3;
if ETHNICITY = "E2" AND RACE = "3" THEN GROUP = "1";
if ETHNICITY = "E2" AND RACE = "5" THEN GROUP = "2";
IF ETHNICITY = "E1" THEN GROUP = "3";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks so much for your expertise and time.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 00:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959867#M43112</guid>
      <dc:creator>whyamihere</dc:creator>
      <dc:date>2025-02-21T00:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: how do you combine two variables into one variable in the same dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959868#M43113</link>
      <description>&lt;P&gt;There's no equals sign in a DATA statement and LIBREFs are limited to 8 characters so I've shortened APPENDICITIS to APP. This logic is a bit better:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA APP.PROJECT3;
  set ???; * Need to read your input dataset;
if ETHNICITY = "E2" AND RACE = "3" THEN GROUP = "1";
else if ETHNICITY = "E2" AND RACE = "5" THEN GROUP = "2";
else IF ETHNICITY = "E1" THEN GROUP = "3";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Feb 2025 00:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959868#M43113</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2025-02-21T00:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: how do you combine two variables into one variable in the same dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959870#M43114</link>
      <description>You could create a new variable by combining these two variable ,and create a format to get this GROUP variable, like:&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt; set have;&lt;BR /&gt; new=catx(' ',ETHNICITY ,RACE );&lt;BR /&gt;run;&lt;BR /&gt;proc format;&lt;BR /&gt;value $ fmt&lt;BR /&gt;'E2 3'='1'&lt;BR /&gt;'E2 5'='2'&lt;BR /&gt;'E1'    ='3'&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data want;&lt;BR /&gt; set have;&lt;BR /&gt;group=put(new,$fmt.);&lt;BR /&gt;run;</description>
      <pubDate>Fri, 21 Feb 2025 01:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959870#M43114</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-02-21T01:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: how do you combine two variables into one variable in the same dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959871#M43115</link>
      <description>&lt;P&gt;You need to use a valid data step.&amp;nbsp; Can you fix that?&lt;/P&gt;
&lt;P&gt;Your code is only assigning values to the new variable for 3 of the possible 32 combinations of your two variables.&lt;/P&gt;
&lt;P&gt;RACE has 7 valid values and I assume could also have missing values, so 8 possible values.&lt;/P&gt;
&lt;P&gt;ETHNICITY has 3 valid values and again I assume could also have missing value, so 4 possible values.&lt;/P&gt;
&lt;P&gt;8*4= 32 possible combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you just want group to be missing for the other 31 possible combinations?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 01:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959871#M43115</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-21T01:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: how do you combine two variables into one variable in the same dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959874#M43116</link>
      <description>&lt;P&gt;Thanks for responding. What do you mean by using a valid data step? I have bitten off more than I can chew in this class but really want to finish, so please dumb it down for me. My instructions only want me to analyze these 3 values in relationship to mean age.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 02:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959874#M43116</guid>
      <dc:creator>whyamihere</dc:creator>
      <dc:date>2025-02-21T02:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: how do you combine two variables into one variable in the same dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959888#M43117</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/473774"&gt;@whyamihere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for responding. What do you mean by using a valid data step? I have bitten off more than I can chew in this class but really want to finish, so please dumb it down for me. My instructions only want me to analyze these 3 values in relationship to mean age.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Data step starts with a DATA statement that names the dataset(s) it is creating.&lt;/P&gt;
&lt;P&gt;It needs to have a source of data.&amp;nbsp; If that is an existing dataset then you need a SET statement.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Feb 2025 03:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-you-combine-two-variables-into-one-variable-in-the-same/m-p/959888#M43117</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-21T03:25:38Z</dc:date>
    </item>
  </channel>
</rss>

