12-05-2014 04:45 PM
Just learning SAS EG, and this has me completely stumped. I would like to recode a variable dependent on the value of a different variable for the same row. The example I am working with is this: Males do not menstruate, so I would want to exclude the age of menstruation for Males. I attempted to create a recoded column marking the age of menstruation as missing for males using a CASE statement, but my new column had 1s and 0s instead of the original value. The advanced expression was:
WHEN 'Gender' = 'M' THEN 'AgeMenst' = .
ELSE 'AgeMenst' = 'AgeMenst'
What am I doing wrong? I have tried multiple different combinations. I've tried leaving out the ELSE statement.
12-05-2014 05:00 PM
This is what I get when using that format (the variable names are actually 'MnstAge Recoded' and 'Gender Recoded'). Any ideas? Have also tried with 'M' instead of M.
12-05-2014 05:08 PM
This looks like a code generation error with non-standard variables names, and I'm pretty sure that it has been addressed in a SAS Enterprise Guide hotifx. What version of SAS Enterprise Guide are you running? Check to make sure that you have the latest fixes.
12-05-2014 05:11 PM
I'm using 4.3. I apologize, because I'm pretty new to this--is there a fix for this version, or would I be better off renaming my variables?
12-05-2014 05:14 PM
Are those actually your variable names? SAS variable names can't contain spaces or special characters unless you have the system option validvarname set to any, which isn't recommended.
Is age already calculated and, if so, what is the variable name?
12-05-2014 05:22 PM
Then try leaving the quote but making the other changes, and storing it in a new variable.
WHEN 'Gender Recoded' = 'M' THEN .
ELSE 'MnstAge Recoded'
END as New_Age_Menst
12-07-2014 10:04 PM
Reeza's code still needs a little adjustment:
WHEN 'Gender Recoded'n = 'M' THEN .
ELSE 'MnstAge Recoded'n
END as New_Age_Menst
As Arthur noted, SAS variable names don't normally contain spaces or special characters. If you want to refer to variables with a space in the name you need to surround the name with quote marks and follow it with the n modifier.