<?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 Simple if then else statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simple-if-then-else-statement/m-p/389150#M93304</link>
    <description>&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;I have i doubt in if then else statement execution.Below is the query :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data levels;&lt;BR /&gt;input name$ level;&lt;BR /&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;run;&lt;BR /&gt;data work.expertise;&lt;BR /&gt;set work.levels;&lt;BR /&gt;put 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;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above SAS program shows that the&amp;nbsp;&lt;STRONG&gt;Variable EXPERTISE contains :&amp;nbsp;Low, Medium, and Unknown only.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;in the ouput after print.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I don't undersrtand how does "&lt;SPAN&gt;expertise = 'High'; " in the last else statement is not considered for level=4???&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;As Currently it shows that&amp;nbsp;for level=4 it considers "expertise = 'Medium".&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Aug 2017 16:39:48 GMT</pubDate>
    <dc:creator>rajvir</dc:creator>
    <dc:date>2017-08-18T16:39:48Z</dc:date>
    <item>
      <title>Simple if then else statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-if-then-else-statement/m-p/389150#M93304</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;I have i doubt in if then else statement execution.Below is the query :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data levels;&lt;BR /&gt;input name$ level;&lt;BR /&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;run;&lt;BR /&gt;data work.expertise;&lt;BR /&gt;set work.levels;&lt;BR /&gt;put 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;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above SAS program shows that the&amp;nbsp;&lt;STRONG&gt;Variable EXPERTISE contains :&amp;nbsp;Low, Medium, and Unknown only.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;in the ouput after print.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I don't undersrtand how does "&lt;SPAN&gt;expertise = 'High'; " in the last else statement is not considered for level=4???&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;As Currently it shows that&amp;nbsp;for level=4 it considers "expertise = 'Medium".&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 16:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-if-then-else-statement/m-p/389150#M93304</guid>
      <dc:creator>rajvir</dc:creator>
      <dc:date>2017-08-18T16:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Simple if then else statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-if-then-else-statement/m-p/389151#M93305</link>
      <description>&lt;P&gt;I have corrected your program:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt; levels;&lt;/P&gt;&lt;P&gt;input name$ level;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;Frank 1&lt;/P&gt;&lt;P&gt;Joan 2&lt;/P&gt;&lt;P&gt;Sui 2&lt;/P&gt;&lt;P&gt;Jose 3&lt;/P&gt;&lt;P&gt;Burt 4&lt;/P&gt;&lt;P&gt;Kelly .&lt;/P&gt;&lt;P&gt;Juan 1&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; work.expertise;&lt;/P&gt;&lt;P&gt;set work.levels;&lt;/P&gt;&lt;P&gt;put level;&lt;/P&gt;&lt;P&gt;if level = &lt;STRONG&gt;.&lt;/STRONG&gt; then&lt;/P&gt;&lt;P&gt;expertise = 'Unknown';&lt;/P&gt;&lt;P&gt;else if level = &lt;STRONG&gt;1&lt;/STRONG&gt; then&lt;/P&gt;&lt;P&gt;expertise = 'Low';&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;else if level = 2 or level= 3 then /*notice here*/&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;expertise = 'Medium';&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;expertise = 'High';&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 16:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-if-then-else-statement/m-p/389151#M93305</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-08-18T16:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Simple if then else statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-if-then-else-statement/m-p/389161#M93309</link>
      <description>&lt;P&gt;Or use IN&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If level in (2,3) then do ...;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS considers any positive number above 1 as true. So 'level=2 or 3' will always evaluate to TRUE because its&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(level=2) or 3 -&amp;gt; TRUE/FALSE or TRUE -&amp;gt; always TRUE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/158053"&gt;@rajvir&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;I have i doubt in if then else statement execution.Below is the query :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data levels;&lt;BR /&gt;input name$ level;&lt;BR /&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;run;&lt;BR /&gt;data work.expertise;&lt;BR /&gt;set work.levels;&lt;BR /&gt;put 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;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above SAS program shows that the&amp;nbsp;&lt;STRONG&gt;Variable EXPERTISE contains :&amp;nbsp;Low, Medium, and Unknown only.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;in the ouput after print.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;I don't undersrtand how does "&lt;SPAN&gt;expertise = 'High'; " in the last else statement is not considered for level=4???&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;As Currently it shows that&amp;nbsp;for level=4 it considers "expertise = 'Medium".&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 17:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-if-then-else-statement/m-p/389161#M93309</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-18T17:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Simple if then else statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-if-then-else-statement/m-p/389165#M93312</link>
      <description>&lt;P&gt;Many nested if/then/else can get hard to track. There is another structure that often works better when you have 3 or more categories based on a single value. Please see:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data work.expertise;
   set work.levels;
   length expertise $ 8; 
   select (level);
      when (1) expertise='Low' ;
      when (2,3) expertise='Medium' ;
      when (4) expertise='High' ;
      otherwise expertise='Unknown';
   end;
run;&lt;/PRE&gt;
&lt;P&gt;Note that if sometime in the future you add another category or value you may only have to insert the value (such as 5 is also high when(4,5) ... Or if you add a 5 for "Very High" then only need to insert when (5) expetise='Very High'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However a value based on single variable may be better to have a custom format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value expertise
1     ='Low' 
2,3   ='Medium' 
4     ='High' 
other ='Unknown'
;
run;

proc print data=work.levels;
   format level expertise.;
run;&lt;/PRE&gt;
&lt;P&gt;Note that such a format works when used with analysis procedures:&lt;/P&gt;
&lt;PRE&gt;proc freq data=work.levels;
   tables level /missing;
   format level expertise.;
run;&lt;/PRE&gt;
&lt;P&gt;Which has an added benefit of creating a new format and using in the procedure to create different groups without having to add any additional variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 17:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-if-then-else-statement/m-p/389165#M93312</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-18T17:23:32Z</dc:date>
    </item>
  </channel>
</rss>

