## Creating new variable from 2 different variables

Occasional Contributor
Posts: 7

# Creating new variable from 2 different variables

I need to create a new variable called 'strata' in which it will have following categories 1- White, 2 - African American, 3 = Asian, 4 = Minority and  5 = Hispanic.

I already have existing variable 'Race' from which I can get 1- White, 2 - African American, 3 = Asian,.

And other existing variable is 'Ethinicity' from which I can get 5 = Hispanic.

Now my issue is how should i create 'strata' variable? if i use the if/else statement it creates additional category which do not fir any 5 categories (listed above).

This what i have used -

if mrace = 2 then strata = 1; *White*;

else if mrace = 3 THEN strata = 2; *Black*;

else if HISP_BC =1 then strata = 3; *Hispanic;

else if mrace = 1 then strata = 4; *Asian;

else if (mrace = 3 or mrace=1 or Hisp_BC = 1) then strata = 5; *Minority;

run;

Super Contributor
Posts: 275

## Re: Creating new variable from 2 different variables

There will overlap in strata=5 with others (strata 1 and 3) if you define (mrace = 3 or mrace=1 or Hisp_BC = 1) then

strata = 5. You could define as

else if  mrace=4 then strata = 5  *Other;

,

Super User
Posts: 9,599

## Re: Creating new variable from 2 different variables

Sorry, really not following what your question is.  The if statement looks fine, assuming that's your data.  What do you mean by "creates additional category"?  Show some test data and required output.

Valued Guide
Posts: 864

## Re: Creating new variable from 2 different variables

For your purpose here if then else doesn't do what you want it to.

Drop the else and just have:

This what i have used -

if mrace = 2 then strata = 1; *White*;

if mrace = 3 THEN strata = 2; *Black*;

if HISP_BC =1 then strata = 3; *Hispanic;

if mrace = 1 then strata = 4; *Asian;

if (mrace = 3 or mrace=1 or Hisp_BC = 1) then strata = 5; *Minority;

run;

Discussion stats
• 3 replies
• 185 views
• 0 likes
• 4 in conversation