Reputation: 73
I am using the SAS-University edition. I need to create a new ethnicity variable based on existing sub ethnicity. Is there a way to select 'WHITE all' instead of specifying 'WHITE-RUSSIAN' or 'WHITE-EUROPEAN' and create the new variable.
Here is my code.
data agg1;
set agg;
if ethnicity = 'WHITE' then ethnicity1= 'white' ;
if ethnicity = 'WHITE-RUSSIAN' then ethnicity1= 'white' ;
if ethnicity = 'WHITE-EUROPEAN' then ethnicity1= 'white';
.
.
run ;
Upvotes: 1
Views: 454
Reputation: 1792
Assuming the values of the ethnicity
variable are always in the format '<main>-<sub>'
, you can reduce this to one line and zero if
statements:
data agg1;
set add;
ethnicity1=scan(ethnicity,1,'-');
run;
Upvotes: 3
Reputation: 9569
Use a :
modifier:
if ethnicity eq: 'WHITE' then ethnicity1= 'white' ;
Upvotes: 5