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!
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:
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.
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...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.