BookmarkSubscribeRSS Feed
krath
Calcite | Level 5

How do I change a variable Ex: Race that is already coded AA or W for African American or white into a simple "1" or "0"??? I cannot find this on SAS Help. TIA.

2 REPLIES 2
PaigeMiller
Diamond | Level 26

I suspect there is more to this problem than you have stated, but nevertheless

 

if race='AA' then race="1";

 

alternatively, assign a FORMAT to race where 'AA' is displayed as "1"

 

 

Which brings up the question, why bother? How is a value of "1" more useful than a value of "AA"?

--
Paige Miller
Tom
Super User Tom
Super User

@krath wrote:

How do I change a variable Ex: Race that is already coded AA or W for African American or white into a simple "1" or "0"??? I cannot find this on SAS Help. TIA.


Do you have character variable that has value 'AA' or 'W'?

Do you want a numeric variable? Or a character variable?

 

If you want a numeric variable then you need to make a new variable.

So if the variable only ever has AA or W (and non are blank or have other values) then you could just assign the result of a boolean expression to your new variable.  So this step will create RACEN that will be 1 when RACE is AA and 0 otherwise.

data want;
  set have;
  racen = (race='AA');
run;

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore 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
  • 2 replies
  • 1310 views
  • 2 likes
  • 3 in conversation