<?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: A combined IF statement,  OR  two separate IF statements   OR SELECT ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-combined-IF-statement-OR-two-separate-IF-statements-OR-SELECT/m-p/907054#M358102</link>
    <description>&lt;P&gt;I doubt it matters.&amp;nbsp; The extra code to implement the extra IF probably erases any gain from eliminating one of the comparisons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only want to run ONE of the DO/END blocks then use IF/THEN/ELSE IF .... logic.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (L1Num LE Xi LT U1Num) then do; ....; end;
else if (L2Num LE Xi LT U2Num) then do; ....; end;
else if (L3Num LE Xi LT U3Num) then do; ....; end;
else if (L4Num LE Xi LT U4Num) then do; ....; end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will more closely match the SELECT pattern.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why do you think you need to use GOTO?&lt;/P&gt;
&lt;P&gt;Are you not just going to the next statement after the IF/SELECT block?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what is READNEXT?&amp;nbsp; A data step will automatically loop over its inputs.&amp;nbsp; Why would you need to "read" some "next" something or other?&lt;/P&gt;</description>
    <pubDate>Fri, 08 Dec 2023 17:20:38 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-12-08T17:20:38Z</dc:date>
    <item>
      <title>A combined IF statement,  OR  two separate IF statements   OR SELECT ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-combined-IF-statement-OR-two-separate-IF-statements-OR-SELECT/m-p/907004#M358094</link>
      <description>&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;Hi!&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="georgia,palatino"&gt;My question:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;Is it fast to write:&amp;nbsp;&amp;nbsp;&lt;FONT face="helvetica"&gt;If&amp;nbsp; &amp;nbsp;LNum LE&amp;nbsp; &amp;nbsp;Xi&amp;nbsp; LT&amp;nbsp; &amp;nbsp;UNum then do; .... end;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;or is it better to write:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;If&amp;nbsp; &amp;nbsp;Xi&amp;nbsp; LT&amp;nbsp; UNum&amp;nbsp; then do;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;If LNum LE&amp;nbsp; Xi then do;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;........&amp;nbsp; end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a simplified part of the real problem:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;&amp;nbsp;&lt;FONT face="helvetica"&gt;If&amp;nbsp; &amp;nbsp;L1Num LE&amp;nbsp; &amp;nbsp;Xi&amp;nbsp; LT&amp;nbsp; &amp;nbsp;U1Num then do; ....;&amp;nbsp; GOTO Readnext; end;&lt;BR /&gt;&amp;nbsp;If&amp;nbsp; &amp;nbsp;L2Num LE&amp;nbsp; &amp;nbsp;Xi&amp;nbsp; LT&amp;nbsp; &amp;nbsp;U2Num then do; ....;&amp;nbsp; GOTO Readnext; end;&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;&lt;FONT face="helvetica"&gt;If&amp;nbsp; &amp;nbsp;L3Num LE&amp;nbsp; &amp;nbsp;Xi&amp;nbsp; LT&amp;nbsp; &amp;nbsp;U3Num then do; ....;&amp;nbsp; GOTO Readnext; end;&lt;BR /&gt;If&amp;nbsp; &amp;nbsp;L4Num LE&amp;nbsp; &amp;nbsp;Xi&amp;nbsp; LT&amp;nbsp; &amp;nbsp;U4Num then do; ....;&amp;nbsp; GOTO Readnext; end;&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;&lt;FONT face="helvetica"&gt;etc.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;&lt;FONT face="helvetica"&gt;If the condition is TRUE, then I want to execute the statements in the do-end. The last statement is a jump out GOTTO Readnext; to read/fetch new data values.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;&lt;FONT face="helvetica"&gt;There is also a Select statment in SAS:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;&lt;FONT face="helvetica"&gt;Select;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;&lt;FONT face="helvetica"&gt;&amp;nbsp; &amp;nbsp;when (L1Num LE&amp;nbsp; &amp;nbsp;Xi&amp;nbsp; LT&amp;nbsp; &amp;nbsp;U1Num)&amp;nbsp; do; ....;&amp;nbsp; GOTO Readnext; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="georgia,palatino"&gt;&lt;FONT face="helvetica"&gt;when (L2Num LE&amp;nbsp; &amp;nbsp;Xi&amp;nbsp; LT&amp;nbsp; &amp;nbsp;U2Num)&amp;nbsp; do; ....;&amp;nbsp; GOTO Readnext; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;when (L3Num LE&amp;nbsp; &amp;nbsp;Xi&amp;nbsp; LT&amp;nbsp; &amp;nbsp;U3Num)&amp;nbsp; do; ....;&amp;nbsp; GOTO Readnext; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;when (L4Num LE&amp;nbsp; &amp;nbsp;Xi&amp;nbsp; LT&amp;nbsp; &amp;nbsp;U4Num)&amp;nbsp; do; ....;&amp;nbsp; GOTO Readnext; end;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;&lt;FONT face="helvetica"&gt;&amp;nbsp; &amp;nbsp;otherwise;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;&lt;FONT face="helvetica"&gt;end;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino"&gt;I am using SAS ODA (SAS on a Linux computer). Quite good. BUT the cpu-times differ with 5-10% between different runs, a few minutes earlier. This means that it is "slightly difficult" to compare the cpu-times.&lt;BR /&gt;I have lots and lots of data and many, many if-statements /Br AndersS&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 16:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-combined-IF-statement-OR-two-separate-IF-statements-OR-SELECT/m-p/907004#M358094</guid>
      <dc:creator>AndersS</dc:creator>
      <dc:date>2023-12-08T16:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: A combined IF statement,  OR  two separate IF statements   OR SELECT ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-combined-IF-statement-OR-two-separate-IF-statements-OR-SELECT/m-p/907054#M358102</link>
      <description>&lt;P&gt;I doubt it matters.&amp;nbsp; The extra code to implement the extra IF probably erases any gain from eliminating one of the comparisons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only want to run ONE of the DO/END blocks then use IF/THEN/ELSE IF .... logic.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (L1Num LE Xi LT U1Num) then do; ....; end;
else if (L2Num LE Xi LT U2Num) then do; ....; end;
else if (L3Num LE Xi LT U3Num) then do; ....; end;
else if (L4Num LE Xi LT U4Num) then do; ....; end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will more closely match the SELECT pattern.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why do you think you need to use GOTO?&lt;/P&gt;
&lt;P&gt;Are you not just going to the next statement after the IF/SELECT block?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what is READNEXT?&amp;nbsp; A data step will automatically loop over its inputs.&amp;nbsp; Why would you need to "read" some "next" something or other?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 17:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-combined-IF-statement-OR-two-separate-IF-statements-OR-SELECT/m-p/907054#M358102</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-08T17:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: A combined IF statement,  OR  two separate IF statements   OR SELECT ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-combined-IF-statement-OR-two-separate-IF-statements-OR-SELECT/m-p/907194#M358141</link>
      <description>Many Thanks. /Br AndersS</description>
      <pubDate>Sun, 10 Dec 2023 17:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-combined-IF-statement-OR-two-separate-IF-statements-OR-SELECT/m-p/907194#M358141</guid>
      <dc:creator>AndersS</dc:creator>
      <dc:date>2023-12-10T17:07:36Z</dc:date>
    </item>
  </channel>
</rss>

