<?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 Re: If then else character variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-character-variable/m-p/578915#M164276</link>
    <description>&lt;P&gt;have you tried using compress and upcase to the variables to confirm that you match case sensitivity and that there are not trailing spaces?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;posting sample data in a data step helps because we don't see what you are looking at based on your statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Aug 2019 15:19:04 GMT</pubDate>
    <dc:creator>VDD</dc:creator>
    <dc:date>2019-08-03T15:19:04Z</dc:date>
    <item>
      <title>If then else character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-character-variable/m-p/578914#M164275</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using SAS 9.4 and I'm trying to recode a variable called PHQ_9_Severity into "Normal" "Mild" "Moderate" and "Severe". The original data set has&amp;nbsp;"Normal" "Mild" "Moderate" "Moderately Severe" and "Severe". I'm trying to make "Moderately Severe" and "Severe" output as "Severe". When I run this code, it prints all of my observations but changes all of the observations that are "Mild" "Moderately Severe" and "Severe" to "Severe" and leaves "Normal" as is leaving me with only two groups.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data nallergy.phq;&lt;BR /&gt;set nallergy.phq9;&lt;BR /&gt;if PHQ_9_Severity = "Mild" then PHQ9Severity="Mild";&lt;BR /&gt;if PHQ_9_Severity = "Moderate" then PHQ9Severity="Moderate";&lt;BR /&gt;if PHQ_9_Severity = "Normal" then PHQ9Severity="Normal";&lt;BR /&gt;else PHQ9Severity = "Severe";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't figure out what I'm doing wrong. Thank you in advance!!&lt;/P&gt;</description>
      <pubDate>Sat, 03 Aug 2019 15:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-character-variable/m-p/578914#M164275</guid>
      <dc:creator>r_trivedi</dc:creator>
      <dc:date>2019-08-03T15:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: If then else character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-character-variable/m-p/578915#M164276</link>
      <description>&lt;P&gt;have you tried using compress and upcase to the variables to confirm that you match case sensitivity and that there are not trailing spaces?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;posting sample data in a data step helps because we don't see what you are looking at based on your statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Aug 2019 15:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-character-variable/m-p/578915#M164276</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-08-03T15:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: If then else character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-character-variable/m-p/578916#M164277</link>
      <description>&lt;P&gt;You need ELSE in a number of places, so that the last line only executes if all the other conditions fail. If you only put ELSE at the end, you get incorrect results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if PHQ_9_Severity = "Mild" then PHQ9Severity="Mild";
else if PHQ_9_Severity = "Moderate" then PHQ9Severity="Moderate";
else if PHQ_9_Severity = "Normal" then PHQ9Severity="Normal";
else PHQ9Severity = "Severe";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Aug 2019 15:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-character-variable/m-p/578916#M164277</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-03T15:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: If then else character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-else-character-variable/m-p/579153#M164368</link>
      <description>&lt;P&gt;You may not even need a new variable. Consider:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value $sev
"Normal" ="Normal"
"Mild"   ="Mild"
"Moderate"="Moderate" 
"Moderately Severe","Severe"="Severe"
;
run;


proc freq data=nalergy.phq9;
   table PHQ_9_Severity ;
   format PHQ_9_Severity $sev.;
run;&lt;/PRE&gt;
&lt;P&gt;Groups created by format levels are honored by almost all of the SAS analysis, reporting or graphing procedures.&lt;/P&gt;
&lt;P&gt;One big advantage of custom format like this is that you do not need to keep adding variable. If latter you want to analyze on three groups such as "Normal" "Mild/Moderate" and "Moderately Severe/Sever" or "Normal" "Mild" "Moderate/Moderately Severe" "Severe" you only need to create a new format.&lt;/P&gt;
&lt;P&gt;Another advantage is if you have multiple variables that have the same coding scheme you can apply the format to those variables as well with a single format statement. Or if you need the different levels in analysis then one format to one variable and a different to others.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 15:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-else-character-variable/m-p/579153#M164368</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-05T15:10:09Z</dc:date>
    </item>
  </channel>
</rss>

