BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sackey
Calcite | Level 5

Hello,

I am inexperienced in SAS and need some help.

I am analyzing some student survey data which had a ‘race’ variable where respondents had the option to select more than one race category. Because of that I have 6 separate race variables.

Variable name

Label

Q3_1

American Indian or Alaska Native

Q3_2

Asian

Q3_3

White

Q3_4

Black or African American

Q3_5

Hispanic or Latino

Q3_6

Native Hawaiian or Other Pacific Islander

I am trying to create one Race variable for analysis and want to add a category of ‘multiracial’ for any person who selects more than one Race. I will want SAS to drop the race categories (Q3_1-Q3_6) for a person who is ‘multiracial’ so that I don’t have multiple lines of data per person however I am unable to do that (highlighted section) and will appreciate any help.

 

data five;
set four;
length race $ 16;
keep id race;
if Q3_1 then do;
	race='American Indian or Alaska Native';
	output;
	end;
if Q3_2 then do;
	race='Asian';
	output;
	end;
if Q3_3 then do;
	race='White';
	output;
	end;
if Q3_4 then do;
	race='Black or African American';
	output;
	end;
if Q3_5 then do;
	race='Hispanic or latino';
	output;
	end;
if Q3_6 then do;
	race='Native Hawaiian or Other Pacific Islander';
	output;
	end;

if q3_3 and q3_5 then do;
	race='multiracial';
	drop q3_3 q3_5;
	output;
	end; 
run;

data six;
merge four five;
by id;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

How are the current variables coded?

Do they have value of 1 if selected and 0 if not?

length race $40;
if sum(of Q3_1 - Q3_6) > 1 then race='Multiracial';
else if Q3_1 then race='American Indian or Alaska Native';
else if Q3_2 then race='Asian';
else if Q3_3 then race='White';
else if Q3_4 then race='Black or African American';
else if Q3_5 then race='Hispanic or latino';
else if Q3_6 then race='Native Hawaiian or Other Pacific Islander';
else race='No response';

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

You cannot selectively drop variables. Both variables will be dropped from dataset five.

By merging back with the original dataset four, you will get them back anyway.

How many observations per id do you expect in the final dataset?

sackey
Calcite | Level 5

Thank you Kurt for your response.

I am expecting 1 race observation per id din the final dataset. 

 

Sackey 

Tom
Super User Tom
Super User

How are the current variables coded?

Do they have value of 1 if selected and 0 if not?

length race $40;
if sum(of Q3_1 - Q3_6) > 1 then race='Multiracial';
else if Q3_1 then race='American Indian or Alaska Native';
else if Q3_2 then race='Asian';
else if Q3_3 then race='White';
else if Q3_4 then race='Black or African American';
else if Q3_5 then race='Hispanic or latino';
else if Q3_6 then race='Native Hawaiian or Other Pacific Islander';
else race='No response';
sackey
Calcite | Level 5

Hello Tom,

Thank you so much for your solution. 

 

Sackey 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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