BookmarkSubscribeRSS Feed
Sassybanana
Fluorite | Level 6

Hello!

 

I am currently trying to recode my "race" variable into 5 categories. When I go to create the 5th category labeled as "other" it spits out a bunch of errors. If someone could help me that would be great!

2 REPLIES 2
Kurt_Bremser
Super User

By assigning a numeric missing value (the dot), you implicitly define race as numeric, so you cannot later on store a character value in it. Define it properly as character in a LENGTH statement, and your first IF becomes unnecessary (a value of only blanks is a missing character value).

 

In the future, avoid the hassle of creating and uploading a Word file; instead simply copy/paste the complete log text (code and messages) into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

Patrick
Opal | Level 21

@Sassybanana 

Just delete the first line with where you set race to missing as that's already going to happen in your else case when Mob_s_Race is missing.

Because race also character IF you want to keep the line then it should be:

if MOB_s_Race = ' ' then race=' ';

And another thing you need to change:

MOB_s_Race can only ever have one value at a time. For this reason you need to use OR instead of AND - else the expression will never become true. You also would need to repeat the variable name for such an expression or use the IN operator instead.

Patrick_0-1648935728023.png

if Mob_s_Race='abc' OR Mob_s_Race='abc' ='xyz' OR.... then...

if Mob_s_Race in ('abc', 'xyz', ....) then...

 

It's often also useful to UPCASE() the variable because such character comparisons are case sensitive.

if upcase(Mob_s_Race) in ('ABC', 'XYZ', ....) then...

 

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
  • 2 replies
  • 1013 views
  • 1 like
  • 3 in conversation