<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to convert character variables to missing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variables-to-missing/m-p/857482#M338821</link>
    <description>Hi everybody! I’m having trouble figuring out the problem with my code. I’m trying to set a character variable (disease) to missing (‘ ‘).&lt;BR /&gt;&lt;BR /&gt;Here is what I’ve done.&lt;BR /&gt;Data ill.diseases_2000;&lt;BR /&gt;Set ill.diseases2000;&lt;BR /&gt;&lt;BR /&gt;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 = ‘ ‘;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Any advice and guidance would be greatly appreciated!</description>
    <pubDate>Tue, 07 Feb 2023 04:22:25 GMT</pubDate>
    <dc:creator>lu_king</dc:creator>
    <dc:date>2023-02-07T04:22:25Z</dc:date>
    <item>
      <title>How to convert character variables to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variables-to-missing/m-p/857482#M338821</link>
      <description>Hi everybody! I’m having trouble figuring out the problem with my code. I’m trying to set a character variable (disease) to missing (‘ ‘).&lt;BR /&gt;&lt;BR /&gt;Here is what I’ve done.&lt;BR /&gt;Data ill.diseases_2000;&lt;BR /&gt;Set ill.diseases2000;&lt;BR /&gt;&lt;BR /&gt;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 = ‘ ‘;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Any advice and guidance would be greatly appreciated!</description>
      <pubDate>Tue, 07 Feb 2023 04:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variables-to-missing/m-p/857482#M338821</guid>
      <dc:creator>lu_king</dc:creator>
      <dc:date>2023-02-07T04:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert character variables to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variables-to-missing/m-p/857488#M338823</link>
      <description>&lt;P&gt;You problem is very likely the use of "smart quotes" or the curly looking things pasted: If (illness =&lt;FONT size="6" color="#FF0000"&gt;&lt;STRONG&gt; ‘&lt;/STRONG&gt;&lt;/FONT&gt;ADHD&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&lt;FONT size="6"&gt;’&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Make sure to use the keyboard simple quote: &lt;STRONG&gt;&lt;FONT size="6" color="#FF0000"&gt;' &lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="4" color="#000000"&gt;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.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When&amp;nbsp; you have a bunch of single values instead of a bunch of OR's like you used try the IN operator to reduce typing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;If illness in ( 'ADHD' 'OCD'  'Arthritis'  'andropause'  'Halitosis'  'Alopecia' 'Bronchitis'  
'celiac'  'thrombosis'  'diverticulitis'  'epilepsy'  'hepatitis C'  'gout' 'hepatitisC'  &lt;BR /&gt;'mononucleosis'  'flu' 'nephropathy'  'CJD') then disease = ' ';
&lt;/PRE&gt;
&lt;P&gt;There is a function CALL MISSING that may be better to use instead of the disease=' ' . You could use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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);&lt;/PRE&gt;
&lt;P&gt;Call missing can do multiple variables at the same type and can mix variable types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am a little concerned about your shown mixed case. If you have any&amp;nbsp; 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&lt;/P&gt;
&lt;PRE&gt;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*/&lt;/PRE&gt;
&lt;P&gt;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 &amp;lt;/&amp;gt; or "running man" icon above the message window. The forum main message window reformats text and may introduce&amp;nbsp; or remove characters not actually in you code.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 05:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variables-to-missing/m-p/857488#M338823</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-07T05:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert character variables to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variables-to-missing/m-p/857621#M338875</link>
      <description>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.&lt;BR /&gt;&lt;BR /&gt;Thank you again!</description>
      <pubDate>Tue, 07 Feb 2023 17:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-variables-to-missing/m-p/857621#M338875</guid>
      <dc:creator>lu_king</dc:creator>
      <dc:date>2023-02-07T17:59:57Z</dc:date>
    </item>
  </channel>
</rss>

