The original variable for race has the following categories for participants:
1 = White
2 = African American/Black
3 = Asian
4 = Other
For my analysis, I am only interested in White and African American/Black participants. I want to create a new variable: race_dich_pt using the if then else statement. What do I do with categories 3 and 4?
if race = 1 then race_dich_pt = 1; /*White*/
else if race = 2 then race_dich_pt = 0; /*African American/Black*/
else if race = 3 then race_dich_pt =
else if race = 4 then race_dich_pt =
else if race = . then race_dich_pt = .;
Depends on what you're doing.
In some cases you may exclude them entirely. In other cases, you would include them as a third group combined, such as other.
if race = 1 then race_dich_pt = 1; /*White*/ else if race = 2 then race_dich_pt = 0; /*African American/Black*/ else race_dich_pt = . ;
But you will want to make sure that any analysis or write up explains that using this variable should exclude XX% of records where XX is the percent of everything non-White and non-Black.
Thank you very much for your help with the code and suggestion for how to describe the other %.
The other thing you can do is use a WHERE clause to exclude the observations you don't want. Then there is no need to recode the data. For example,
proc freq data=Have;
where Race=1 or Race=2;
tables Race;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.