BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lu_king
Obsidian | Level 7
Hi everybody! I’m having trouble figuring out the problem with my code. I’m trying to set a character variable (disease) to missing (‘ ‘).

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!
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

lu_king
Obsidian | Level 7
Thank you for such a comprehensive response! It was the combination of the smart quotes and the mixed case, I didn't account for different spellings.

Thank you again!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 468 views
  • 1 like
  • 2 in conversation