- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here is what I’ve done.
Data ill.diseases_2000;
Set ill.diseases2000;
If (illness = ‘ADHD’ OR illness = ‘OCD’ OR illness = ‘Arthritis’ OR illness = ‘andropause’ OR illness = ‘Halitosis’ OR illness = ‘Alopecia’ OR illness = ‘Bronchitis’ OR illness = ‘celiac’ OR illness = ‘thrombosis’ OR illness = ‘diverticulitis’ OR illness = ‘epilepsy’ OR illness = ‘hepatitis C’ OR illness = ‘gout’ OR illness =‘hepatitisC’ Or illness = ‘mononucleosis’ OR illness = ‘flu’ OR illness = ‘nephropathy’ OR illness = ‘CJD’) then disease = ‘ ‘;
run;
Whenever I run the code the entire new variable (disease) is blank not just the ones I wanted. I thought maybe it’s too many in a row so I broke up the if, then statement and it’s the same thing.
Any advice and guidance would be greatly appreciated!
- Tags:
- programming
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you again!