BookmarkSubscribeRSS Feed
mar0000
Obsidian | Level 7

I have a dataset with race and ID:

 

ID        Race      

1           White

1           Declined to Answer

2           Alaskan Native   

3           Unknown       

3           African American             

4           White

4           Native Hawaiian

 

I would like for the dataset to have one ID and one race. If the race is 'Unknown' or 'Declined to Answer' I would like to have Race be valued as the the race that is known (White for ID #1 and African American for ID #3). If there are two races valued, I would like the value to be the more uncommon race (Native Hawaiian for ID #4). I would ideally like to have a dataset that looks like:

 

ID        Race      

1           White

2           Alaskan Native   

3           African American             

4           Native Hawaiian

 

I appreciate any help!!

6 REPLIES 6
Reeza
Super User
1. Recode Unknown/Declined to Answer to a SAS missing value or special missing if you still want to uniquely identify the records.
2. Use PROC FREQ to create a ranking of the races
3. Merge the rank data with the actual data - including the rank
4. Sort your data now by rank from #3, take the first record per ID
mar0000
Obsidian | Level 7

Can you provide some example code? This explanation isn't very clear to me. Thank you

Reeza
Super User
Please clarify - which portion is not clear? What did you try so far and what did you get? Please include any code and log.
mar0000
Obsidian | Level 7

I have a dataset with race and ID:

 

ID        Race      

1           White

1           Declined to Answer

2           Alaskan Native   

3           Unknown       

3           African American             

4           White

4           Native Hawaiian

 

I would like for the dataset to have one ID and one race. If the race is 'Unknown' or 'Declined to Answer' I would like to have Race be valued as the the race that is known (White for ID #1 and African American for ID #3). If there are two races valued, I would like the value to be the more uncommon race (Native Hawaiian for ID #4). I would ideally like to have a dataset that looks like:

 

ID        Race      

1           White

2           Alaskan Native   

3           African American             

4           Native Hawaiian

 

I appreciate any help!!

Reeza
Super User
FYI - I merged your posts as they're identical. If you have a reason for reposting please let us know.
andreas_lds
Jade | Level 19

How do you define "uncommon race"?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 464 views
  • 1 like
  • 3 in conversation