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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—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
  • 2 replies
  • 918 views
  • 2 likes
  • 3 in conversation