I'm trying to apply a format to this table.
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;
My racex variable looks nothing like the format I created. can anyone point to what I'm doing wrong?
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).
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?
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.
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).
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.