BookmarkSubscribeRSS Feed
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

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

5 REPLIES 5
HB
Barite | Level 11 HB
Barite | Level 11

trim(race_desc) in the data step?

 

 

ChrisNZ
Tourmaline | Level 20

strip() to remove leading and trailing spaces

compbl() to remove extraneous inner spaces

You might want to upcase() too,

 

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

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?

ChrisNZ
Tourmaline | Level 20

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. 

 

 

Tom
Super User Tom
Super User

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.

 

https://documentation.sas.com/?docsetId=proc&docsetVersion=9.4&docsetTarget=p1pmw90bl3jzgdn1w4202kcl...

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 922 views
  • 2 likes
  • 4 in conversation