<?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 Statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/686921#M208495</link>
    <description>&lt;P&gt;Sounds like an issue with understanding the complexities of English language. The phrase "x follows y" and "x is followed by y" imply opposite orders for X and Y.&amp;nbsp; The first means the sequence is Y -&amp;gt; X and the second means X -&amp;gt; Y.&lt;/P&gt;</description>
    <pubDate>Sat, 26 Sep 2020 13:50:34 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-09-26T13:50:34Z</dc:date>
    <item>
      <title>IF-THEN/ELSE Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/682107#M206456</link>
      <description>&lt;P&gt;Hi Members,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the SAS documentation, it says " The ELSE statement, if used, must immediately follow the IF-THEN statement."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to understand the above meaning but is confused when the below codes are valid and at line 6, the else statement does not immediately follow the if-then statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone can enlighten me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data storm_cat;
    set pg1.storm_summary;
    keep Name Basin MinPressure StartDate PressureGroup;
    if MinPressure=. then PressureGroup=.;
    &lt;SPAN class="hilight"&gt;else if MinPressure&amp;lt;=920 then PressureGroup=1;&lt;/SPAN&gt;
    &lt;SPAN class="hilight"&gt;else PressureGroup=0;&lt;/SPAN&gt;
run; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 04:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/682107#M206456</guid>
      <dc:creator>marcuswong</dc:creator>
      <dc:date>2020-09-08T04:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN/ELSE Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/682113#M206459</link>
      <description>&lt;P&gt;That's true when you have only one ELSE statement, but if you have more than one ELSE, then they can follow one after the other as long as the first ELSE in the sequence is preceded by an IF statement.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 04:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/682113#M206459</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-09-08T04:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN/ELSE Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/682121#M206462</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;the else statement does not immediately follow the if-then statement.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;It does.&lt;/P&gt;
&lt;PRE&gt;data storm_cat;
    set pg1.storm_summary;
    keep Name Basin MinPressure StartDate PressureGroup;
    &lt;FONT color="#FF0000"&gt;if&lt;/FONT&gt; MinPressure=. &lt;FONT color="#FF0000"&gt;then&lt;/FONT&gt; PressureGroup=.;
    &lt;SPAN class="hilight"&gt;&lt;FONT color="#FF0000"&gt;else &lt;FONT color="#0000FF"&gt;if &lt;/FONT&gt;&lt;/FONT&gt;MinPressure&amp;lt;=920 &lt;FONT color="#0000FF"&gt;then&lt;/FONT&gt; PressureGroup=1;&lt;/SPAN&gt;
    &lt;SPAN class="hilight"&gt;&lt;FONT color="#0000FF"&gt;else &lt;/FONT&gt;PressureGroup=0;&lt;/SPAN&gt;
run; &lt;/PRE&gt;
&lt;P&gt;The red ELSE follows the red IF, and the blue ELSE follows the blue IF.&lt;/P&gt;
&lt;P&gt;The catch here is that the blue IF has been made part of the red ELSE statement, hence the confusion. If DO blocks were used, the sequence would be (slightly) clearer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The bottom line is this: you cannot use a ELSE statement when there is not a corresponding IF-THEN just before.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 07:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/682121#M206462</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-08T07:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN/ELSE Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/683204#M206912</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp; Thank you for the guidance!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 09:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/683204#M206912</guid>
      <dc:creator>marcuswong</dc:creator>
      <dc:date>2020-09-11T09:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN/ELSE Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/683227#M206922</link>
      <description>&lt;P&gt;Not sure why you are confused. You have two ELSE and two THEN.&amp;nbsp; Perhaps if you changed your indentation style it would be clearer?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if MinPressure=. then PressureGroup=.;
                 else if MinPressure&amp;lt;=920 then PressureGroup=1;
                                          else PressureGroup=0;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Sep 2020 12:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/683227#M206922</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-11T12:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN/ELSE Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/686881#M208479</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;I&amp;nbsp;&lt;SPAN&gt;misinterpret the sentence in the SAS documentation that after "else" must follow by "if-then".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;instead, I should learn it as ''else" cannot be used alone and "else" must always follow behind a "if-then".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please let me know if I am learning correctly?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Sep 2020 02:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/686881#M208479</guid>
      <dc:creator>marcuswong</dc:creator>
      <dc:date>2020-09-26T02:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN/ELSE Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/686918#M208494</link>
      <description>&lt;P&gt;To help you understand the code, let's expand it a little, and slightly change the indentation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data storm_cat;
set pg1.storm_summary;
keep Name Basin MinPressure StartDate PressureGroup;
if MinPressure = .
then PressureGroup = .;
else do;
  if MinPressure &amp;lt;= 920
  then PressureGroup = 1;
  else PressureGroup = 0;
end;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you can see that the second if-then-else follows the exact same pattern as the first if-then-else.&lt;/P&gt;
&lt;P&gt;Since, logically, a if-then-else can be used as a single statement, the do/end can be omitted, leading to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if MinPressure = .
then PressureGroup = .;
else if MinPressure &amp;lt;= 920
then PressureGroup = 1;
else PressureGroup = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is what you have originally.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Sep 2020 13:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/686918#M208494</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-26T13:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN/ELSE Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/686921#M208495</link>
      <description>&lt;P&gt;Sounds like an issue with understanding the complexities of English language. The phrase "x follows y" and "x is followed by y" imply opposite orders for X and Y.&amp;nbsp; The first means the sequence is Y -&amp;gt; X and the second means X -&amp;gt; Y.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Sep 2020 13:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/686921#M208495</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-26T13:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN/ELSE Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/687159#M208591</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;Thank you for the guidance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 10:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement/m-p/687159#M208591</guid>
      <dc:creator>marcuswong</dc:creator>
      <dc:date>2020-09-28T10:07:22Z</dc:date>
    </item>
  </channel>
</rss>

