<?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 %else on multiple %ifs statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/else-on-multiple-ifs-statements/m-p/913008#M359876</link>
    <description>&lt;P&gt;Dear experts, I would ask a clarification. Over a set of %if statement, a final %else would be applied to the latest %if condition, or to any of the previous %if conditions ? I believe it's the first one, so question is, how to skip the final %else if any of the previous %if is satisfied?&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jan 2024 17:20:29 GMT</pubDate>
    <dc:creator>dcortell</dc:creator>
    <dc:date>2024-01-25T17:20:29Z</dc:date>
    <item>
      <title>%else on multiple %ifs statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-on-multiple-ifs-statements/m-p/913008#M359876</link>
      <description>&lt;P&gt;Dear experts, I would ask a clarification. Over a set of %if statement, a final %else would be applied to the latest %if condition, or to any of the previous %if conditions ? I believe it's the first one, so question is, how to skip the final %else if any of the previous %if is satisfied?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 17:20:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-on-multiple-ifs-statements/m-p/913008#M359876</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2024-01-25T17:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: %else on multiple %ifs statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-on-multiple-ifs-statements/m-p/913021#M359881</link>
      <description>&lt;P&gt;Your questions isn't very clear.&amp;nbsp; Can you show an example of what you are trying to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the answer might be to use %ELSE %IF.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you can code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;A %then %put A is true;
%else %if &amp;amp;B %then %put B is true;
%else %if &amp;amp;C %then %put C is true;
%else %put A is false and B is false and C is false;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With that structure, the code on the %ELSE statement is only executed if all of the prior %IF and %ELSE %IF statements are false.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 18:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-on-multiple-ifs-statements/m-p/913021#M359881</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-01-25T18:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: %else on multiple %ifs statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-on-multiple-ifs-statements/m-p/913034#M359887</link>
      <description>&lt;P&gt;The net result is just the way&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;described it.&amp;nbsp; However, you may see documentation that says that %else is only executed under two conditions:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The previous %if condition was evaluated, and&lt;/LI&gt;
&lt;LI&gt;The previous %if condition was found to be false.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;This is also correct!&amp;nbsp; How can that also be true?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider applying those conditions to Quentin's example.&amp;nbsp; On the second line, looking at &amp;amp;B, clearly the logic to execute that line depends on:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;SAS examined &amp;amp;A from the previous %if condition, and&lt;/LI&gt;
&lt;LI&gt;SAS found that &amp;amp;A was false.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;When both of those bullet points are true, the software executes %if &amp;amp;B %then ....;&lt;/P&gt;
&lt;P&gt;When &amp;amp;A was true, the software skips evaluating %if &amp;amp;B %then ....;&lt;/P&gt;
&lt;P&gt;So what happens when we get to &amp;amp;C?&amp;nbsp; The software checks:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Did we evaluate the previous %if condiition for &amp;amp;B?&lt;/LI&gt;
&lt;LI&gt;Was it false?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;So when &amp;amp;B was false, the software skips evaluating &amp;amp;C, and never executes %if &amp;amp;C %then ....;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In essence, with a set of %else statements, each one always means was the previous %if condiition evaluated and found to be true.&amp;nbsp; However, the result is the one you hope for:&amp;nbsp; %else requires all the previous %if conditions to be true.&amp;nbsp; The logic behind that, however, is that once a true condition is found, the next %else statement is skipped.&amp;nbsp; Once one is skipped, all the rest are skipped.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 19:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-on-multiple-ifs-statements/m-p/913034#M359887</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-01-25T19:02:39Z</dc:date>
    </item>
  </channel>
</rss>

