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...
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.