Using SAS 9.4
proc format;
value $RACE_DESC 'WHITE' = 'Caucasian'
'BLACK' = 'African American'
'CHINESE','PAKISTANI','OTHER' = 'Other'
'UNKNOWN','NOT APPLICABLE' = 'Unknown';
RUN;
Above is format statement. I believe it is formatted correctly. Is their a way to trim the 'white' 'black' etc. to remove any weird spaces that I am not capturing in my format. (I did try copy and pasting directly from document and it did not work that way either). Thank you
trim(race_desc) in the data step?
strip() to remove leading and trailing spaces
compbl() to remove extraneous inner spaces
You might want to upcase() too,
data raw.DiagSeq_1_2;
set raw.DiagSeq_One;
if RACE = (STRIP('WHITE') OR
RACE = (STRIP('BLACK') OR
RACE = (STRIP('CHINESE') OR
RACE = (STRIP('PAKISTANI') OR
RACE = (STRIP('OTHER') OR
RACE = (STRIP('UNKNOWN') OR
RACE = (STRIP('NOT APPLICABLE');
RUN;
Above is the code I tried, it is a combination of the recommendations but it is not working. Any other thoughts?
Wow.
You seem to have serious misunderstandings about how programming works, and to badly need training.
I doubt the punctual help we can give here is going to take you very far.
To answer the question at hand:
proc format;
value $wood_desc 'WHITE' = 'Birch'
'BLACK' = 'Ebony'
'CHINESE','PAKISTANI','OTHER' = 'Oak'
'UNKNOWN','NOT APPLICABLE' = 'Unknown';
run;
data WANT;
A=' WHiTE';
B=put(strip(compbl(upcase(A))), $wood_desc.);
putlog B=;
run;
B=Birch
I had to change the data as I find yours creepy.
As a European, such data about race/religion/etc is forbidden in many countries as its use only a few decades ago brings back very dark memories.
No. But if you switch to using an INFORMAT instead of a FORMAT then you can use REGEXP or REGEXPE option of the INVALUE statement.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.