BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hello_there
Lapis Lazuli | Level 10

I'm trying to apply a format to this table.

 

Hello_there_0-1610476426727.png

using this code

proc format;*creating formats;
	value $racex
AMERICAN INDIAN OR ALASKA NATIVE="American Indian or Alaska Native"
ASIAN="Asian"
BLACK OR AFRICAN AMERICAN="Black or African American"
NATIVE HAWAIIAN OR OTHER="Native Hawaiian or Other"
PACIFIC ISLANDER="Pacific Islander"
WHITE="White"
MULTIPLE="Multiple"
MISSING="Missing";
run;
	
data finalrace2;
	length raceX $50.;
	set finalrace;
	racex=put (race, $racex.);
run;
proc print data=finalrace2;
run;

Hello_there_1-1610476553999.png

My racex variable looks nothing like the format I created. can anyone point to what I'm doing wrong? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @Hello_there,

 

No, it's not the "OR" that confused the compiler, but the ambiguities that arise when quotes around values consisting of multiple words are missing. Just use quotes on both sides of the equals signs and the format will be created correctly.

 

It's good practice to always use quotes around character strings (where appropriate; not talking about macros, of course) although SAS tolerates unquoted strings in some places (for extreme backward compatibility I guess).

View solution in original post

3 REPLIES 3
Hello_there
Lapis Lazuli | Level 10

hmmm... after pasting the code and seeing I displayed it looks like the problem is the use of the word OR. That's in the name of the race. Is there anyway to fix it? 

PaigeMiller
Diamond | Level 26

In PROC FORMAT, there is no "OR" operator, I think you mean

 

proc format;*creating formats;
	value $racex
'AMERICAN INDIAN','ALASKA NATIVE'="American Indian or Alaska Native"
'ASIAN'="Asian"
'BLACK','AFRICAN AMERICAN'="Black or African American"
/* etc. */
;
run;

 Also, the above code is case sensitive, so 'Black" doesn't get formatted. If that's a problem, it's easy to fix via the UPCASE() function in your DATA step.

--
Paige Miller
FreelanceReinh
Jade | Level 19

Hi @Hello_there,

 

No, it's not the "OR" that confused the compiler, but the ambiguities that arise when quotes around values consisting of multiple words are missing. Just use quotes on both sides of the equals signs and the format will be created correctly.

 

It's good practice to always use quotes around character strings (where appropriate; not talking about macros, of course) although SAS tolerates unquoted strings in some places (for extreme backward compatibility I guess).

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 893 views
  • 1 like
  • 3 in conversation