<?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: Else if - override in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Else-if-override/m-p/843840#M333600</link>
    <description>For the sashelp.class, it did not seem to do the same thing---cl is populated as 1 not 2 although the second condition is true as well.</description>
    <pubDate>Fri, 11 Nov 2022 18:14:42 GMT</pubDate>
    <dc:creator>Tommer</dc:creator>
    <dc:date>2022-11-11T18:14:42Z</dc:date>
    <item>
      <title>Else if - override</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Else-if-override/m-p/843831#M333595</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am working on a few else if conditions to understand how else if works on different variables:&lt;/P&gt;
&lt;P&gt;In the below example 'cl' doesn't get overwritten to 2 which means once the if condition is successful on a record it is not evaluating that record again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data cls;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;if sex="M" then cl=1;&lt;BR /&gt;else if age=14 then cl=2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, in the below example where I am working on same record and running else if on two different variables, it is getting overwritten. I don't understand why it is reading the same record again in else if (it did not in the above example).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tommer_0-1668188339600.png" style="width: 714px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77218iE80C8E812DA1A601/image-dimensions/714x66?v=v2" width="714" height="66" role="button" title="Tommer_0-1668188339600.png" alt="Tommer_0-1668188339600.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data chk;&lt;BR /&gt;set cm1;&lt;BR /&gt;&lt;BR /&gt;if (trtsdtm &amp;lt;= aendtm) then cmfl= 'Y';&lt;BR /&gt;else if (trtsdt &amp;lt;= aendt) then cmfl= 'Y'; &lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 17:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Else-if-override/m-p/843831#M333595</guid>
      <dc:creator>Tommer</dc:creator>
      <dc:date>2022-11-11T17:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Else if - override</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Else-if-override/m-p/843839#M333599</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I don't understand why it is reading the same record again in else if (it did not in the above example).&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A SAS data step works on all records. It applies all the code to all records (unless there is some code to force it to advance to another record).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, this section of code comprising two lines, one beginning with IF and the nnext one beginning with ELSE, are executed on the current record,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (trtsdtm &amp;lt;= aendtm) then cmfl= 'Y';
else if (trtsdt &amp;lt;= aendt) then cmfl= 'Y'; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as there is nothing in your code to tell it to move on the the next record between records. If either or both conditions are true, you get CMFL='Y'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you show working on SASHELP.CLASS does the same thing. The block of code comprising of an IF and an ELSE are run on all records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 18:05:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Else-if-override/m-p/843839#M333599</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-11T18:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: Else if - override</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Else-if-override/m-p/843840#M333600</link>
      <description>For the sashelp.class, it did not seem to do the same thing---cl is populated as 1 not 2 although the second condition is true as well.</description>
      <pubDate>Fri, 11 Nov 2022 18:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Else-if-override/m-p/843840#M333600</guid>
      <dc:creator>Tommer</dc:creator>
      <dc:date>2022-11-11T18:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Else if - override</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Else-if-override/m-p/843841#M333601</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/284458"&gt;@Tommer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;For the sashelp.class, it did not seem to do the same thing---cl is populated as 1 not 2 although the second condition is true as well.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's how IF THEN ELSE works ... when the IF is true on a given record, the ELSE doesn't get applied to that record.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 18:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Else-if-override/m-p/843841#M333601</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-11T18:25:14Z</dc:date>
    </item>
  </channel>
</rss>

