You problem is very likely the use of "smart quotes" or the curly looking things pasted: If (illness = ‘ADHD’
Make sure to use the keyboard simple quote: ' Those quotes aren't expected by the program and do not get treated as valid text indicators so the values were not considered matches as you might expect. Also, you do not show any attempt to set DISEASE to any value other than missing, so I don't know what you would expect to happen. If a value is in the list then set missing. Otherwise do nothing (which leaves a newly created variable as missing). So tell when DISEASE should not be missing and what value it should have.
When you have a bunch of single values instead of a bunch of OR's like you used try the IN operator to reduce typing.
If illness in ( 'ADHD' 'OCD' 'Arthritis' 'andropause' 'Halitosis' 'Alopecia' 'Bronchitis' 'celiac' 'thrombosis' 'diverticulitis' 'epilepsy' 'hepatitis C' 'gout' 'hepatitisC'
'mononucleosis' 'flu' 'nephropathy' 'CJD') then disease = ' ';
There is a function CALL MISSING that may be better to use instead of the disease=' ' . You could use
If illness in ( 'ADHD' 'OCD' 'Arthritis' 'andropause' 'Halitosis' 'Alopecia' 'Bronchitis' 'celiac' 'thrombosis' 'diverticulitis' 'epilepsy' 'hepatitis C' 'gout' 'hepatitisC' 'mononucleosis' 'flu' 'nephropathy' 'CJD') then call missing (disease);
Call missing can do multiple variables at the same type and can mix variable types.
I am a little concerned about your shown mixed case. If you have any values of 'Adhd' 'adhd' 'AdHd' and such they would not be considered a match as 'ADHD' is not the same as any of those other spellings. I would suggest if you have any possibility of other spellings to do something like
If upcase(illness) in ( 'ADHD' 'OCD' 'ARTHRITIS' 'ANDROPAUSE' 'HALITOSIS' 'ALOPECIA' 'BRONCHITIS' 'CELIAC' 'THROMBOSIS' 'DIVERTICULITIS' 'EPILEPSY' 'HEPATITIS C' 'GOUT' 'HEPATITISC' 'MONONUCLEOSIS' 'FLU' 'NEPHROPATHY' 'CJD') then call missing(disease); /* else disease = what ever your rule is*/
It is a good idea on this forum to paste code into a text or code box opened on the forum by clicking on either the </> or "running man" icon above the message window. The forum main message window reformats text and may introduce or remove characters not actually in you code.
You problem is very likely the use of "smart quotes" or the curly looking things pasted: If (illness = ‘ADHD’
Make sure to use the keyboard simple quote: ' Those quotes aren't expected by the program and do not get treated as valid text indicators so the values were not considered matches as you might expect. Also, you do not show any attempt to set DISEASE to any value other than missing, so I don't know what you would expect to happen. If a value is in the list then set missing. Otherwise do nothing (which leaves a newly created variable as missing). So tell when DISEASE should not be missing and what value it should have.
When you have a bunch of single values instead of a bunch of OR's like you used try the IN operator to reduce typing.
If illness in ( 'ADHD' 'OCD' 'Arthritis' 'andropause' 'Halitosis' 'Alopecia' 'Bronchitis' 'celiac' 'thrombosis' 'diverticulitis' 'epilepsy' 'hepatitis C' 'gout' 'hepatitisC'
'mononucleosis' 'flu' 'nephropathy' 'CJD') then disease = ' ';
There is a function CALL MISSING that may be better to use instead of the disease=' ' . You could use
If illness in ( 'ADHD' 'OCD' 'Arthritis' 'andropause' 'Halitosis' 'Alopecia' 'Bronchitis' 'celiac' 'thrombosis' 'diverticulitis' 'epilepsy' 'hepatitis C' 'gout' 'hepatitisC' 'mononucleosis' 'flu' 'nephropathy' 'CJD') then call missing (disease);
Call missing can do multiple variables at the same type and can mix variable types.
I am a little concerned about your shown mixed case. If you have any values of 'Adhd' 'adhd' 'AdHd' and such they would not be considered a match as 'ADHD' is not the same as any of those other spellings. I would suggest if you have any possibility of other spellings to do something like
If upcase(illness) in ( 'ADHD' 'OCD' 'ARTHRITIS' 'ANDROPAUSE' 'HALITOSIS' 'ALOPECIA' 'BRONCHITIS' 'CELIAC' 'THROMBOSIS' 'DIVERTICULITIS' 'EPILEPSY' 'HEPATITIS C' 'GOUT' 'HEPATITISC' 'MONONUCLEOSIS' 'FLU' 'NEPHROPATHY' 'CJD') then call missing(disease); /* else disease = what ever your rule is*/
It is a good idea on this forum to paste code into a text or code box opened on the forum by clicking on either the </> or "running man" icon above the message window. The forum main message window reformats text and may introduce or remove characters not actually in you code.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.