<?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 ELSE IF CONDITION in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497326#M131777</link>
    <description>&lt;P&gt;Logical operators are resolved after arithmetic operators and expressions. So&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if level = 2 or 3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;resolves to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (level = 2) or (3)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3 (which is not zero or missing) is considered "true", so the condition will always be true, and the "else" never be executed.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Sep 2018 12:03:29 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-09-20T12:03:29Z</dc:date>
    <item>
      <title>IF ELSE IF CONDITION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497308#M131766</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've a dataset test1 where i want to write&amp;nbsp;&lt;SPAN&gt;expertise&amp;nbsp;column based on some condition . when i gave the condition for Medium (else if level = 2 or 3 then) then else condition is not working, however I have a value for else. Can anybody please explain why Else condition is not working and how SAS considering&amp;nbsp;given condition (else if level = 2 or 3).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test1;&lt;BR /&gt;input NAME $ LEVEL;&lt;BR /&gt;if level = . then&lt;BR /&gt;expertise = 'Unknown';&lt;BR /&gt;else if level = 1 then&lt;BR /&gt;expertise = 'Low';&lt;BR /&gt;else if level = 2 or 3 then&lt;BR /&gt;expertise = 'Medium';&lt;BR /&gt;else&lt;BR /&gt;expertise = 'High';&lt;/P&gt;&lt;P&gt;CARDS;&lt;BR /&gt;Frank 1&lt;BR /&gt;Joan 2&lt;BR /&gt;Sui 2&lt;BR /&gt;Jose 3&lt;BR /&gt;Burt 4&lt;BR /&gt;Kelly .&lt;BR /&gt;Juan 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all in advance !!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 11:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497308#M131766</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2018-09-20T11:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: IF ELSE IF CONDITION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497322#M131774</link>
      <description>&lt;P&gt;You need:&lt;/P&gt;
&lt;PRE&gt;else if level in (2,3) then&lt;/PRE&gt;
&lt;P&gt;Or:&lt;/P&gt;
&lt;PRE&gt;else if level=2 or level=3 then&lt;/PRE&gt;
&lt;P&gt;You can't use 2 or 3 like that.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 11:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497322#M131774</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-20T11:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: IF ELSE IF CONDITION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497325#M131776</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/153275"&gt;@singhsahab&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The condition &lt;FONT face="courier new,courier"&gt;level = 2 or 3&lt;/FONT&gt;&amp;nbsp;is true &lt;EM&gt;regardless&lt;/EM&gt; of the value of variable LEVEL because SAS interprets 3 (and numeric values in general) as a Boolean value of its own, like &lt;FONT face="courier new,courier"&gt;(level = 2) or (3)&lt;/FONT&gt;. Hence, the subsequent ELSE statement will not take effect. Numeric values (as Boolean expressions) are evaluated as TRUE if they are nonmissing and not zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 12:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497325#M131776</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-09-20T12:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: IF ELSE IF CONDITION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497326#M131777</link>
      <description>&lt;P&gt;Logical operators are resolved after arithmetic operators and expressions. So&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if level = 2 or 3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;resolves to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (level = 2) or (3)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3 (which is not zero or missing) is considered "true", so the condition will always be true, and the "else" never be executed.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 12:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497326#M131777</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-20T12:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: IF ELSE IF CONDITION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497427#M131839</link>
      <description>&lt;P&gt;If you want to display a given text for values or ranges of values for a single variable consider using FORMATS instead.&lt;/P&gt;
&lt;P&gt;You can apply a format at the time of use so adding a variable is usually not needed and the formats will create groups honored by analysis or graphing procedures.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value expertise
.='Unknown'
1='Low'
2,3='Medium'
other='High'
;
run;
data test1;
input NAME $ LEVEL;
CARDS;
Frank 1
Joan 2
Sui 2
Jose 3
Burt 4
Kelly .
Juan 1
;
run;

proc freq data=test1;
   /* missing is needed to include missing 
      values of the variable in proc freq 
      output
   */
   tables level/missing;
   format level expertise.;
run;&lt;/PRE&gt;
&lt;P&gt;Another advantage of formats is the code for assigning values to ranges can be much more concise then a slew of If/then/else because you can use end of interval indicators:&amp;nbsp; 32.1 - 34.5 includes the ends, 32.1 &amp;lt;- 34.5 excludes 32.1 but includes 32.10004 for example, and 32.1 &amp;lt;-&amp;lt; 34.5 excludes both end points. Additionally you have keywords LOW and HIGH to get from the smallest value or largest value (for numerics) that your SAS session can use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 15:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497427#M131839</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-20T15:17:59Z</dc:date>
    </item>
  </channel>
</rss>

