<?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: AND/ OR conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/AND-OR-conditions/m-p/775327#M246450</link>
    <description>&lt;P&gt;May anyone explain the calculation of Ind_a&lt;/P&gt;
&lt;P&gt;I don't understand how it works,&lt;/P&gt;
&lt;P&gt;why&amp;nbsp; X=5 W=100 Z=90 get ind_a=1??&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ttt;
input x w z;
cards;
5 100 9
5 100 90
8 90 9
;
Run;

Data wanted;
set ttt;
IF x=5 OR (X=2 AND W=3) OR (X=2 AND W=8) AND Z=9 then Ind_a=1;
IF (x=5 OR (X=2 AND W=3) OR (X=2 AND W=8)) AND Z=9 then Ind_b=1;
Run; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Oct 2021 07:33:49 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-10-20T07:33:49Z</dc:date>
    <item>
      <title>AND/ OR conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/AND-OR-conditions/m-p/775320#M246448</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to ask if option1 and option2 are doing same or there is a difference?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/***option1***/
IF x=5 OR (X=2 AND W=3) OR (X=2 AND W=8) AND Z=9 then Ind=1;
/***option2***/
IF (x=5 OR (X=2 AND W=3) OR (X=2 AND W=8)) AND Z=9 then Ind=1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Oct 2021 06:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/AND-OR-conditions/m-p/775320#M246448</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-10-20T06:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: AND/ OR conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/AND-OR-conditions/m-p/775322#M246449</link>
      <description>Different...&lt;BR /&gt;Option 1 sets IND to 1 whenever X is 5.  AND gets evaluated before OR without parentheses.&lt;BR /&gt;&lt;BR /&gt;Option 2 requires Z to be 9 to set IND to 1.</description>
      <pubDate>Wed, 20 Oct 2021 07:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/AND-OR-conditions/m-p/775322#M246449</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-10-20T07:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: AND/ OR conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/AND-OR-conditions/m-p/775327#M246450</link>
      <description>&lt;P&gt;May anyone explain the calculation of Ind_a&lt;/P&gt;
&lt;P&gt;I don't understand how it works,&lt;/P&gt;
&lt;P&gt;why&amp;nbsp; X=5 W=100 Z=90 get ind_a=1??&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ttt;
input x w z;
cards;
5 100 9
5 100 90
8 90 9
;
Run;

Data wanted;
set ttt;
IF x=5 OR (X=2 AND W=3) OR (X=2 AND W=8) AND Z=9 then Ind_a=1;
IF (x=5 OR (X=2 AND W=3) OR (X=2 AND W=8)) AND Z=9 then Ind_b=1;
Run; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 07:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/AND-OR-conditions/m-p/775327#M246450</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-10-20T07:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: AND/ OR conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/AND-OR-conditions/m-p/775330#M246452</link>
      <description>&lt;P&gt;As already mentioned, AND is evaluated first, so this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(X=2 AND W=8) AND Z=9&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is calculated first; it is equivalent to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;X=2 AND W=8 AND Z=9&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;all three conditions need to be satisfied for this part to become true. In your data, this is never the case.&lt;/P&gt;
&lt;P&gt;Similarly, the other AND is evaluated (the brackets are not necessary, but they help in keeping the code clear).&lt;/P&gt;
&lt;P&gt;Then come the ORs, and since X=5 is satisfied in the first two observations, the whole condition will become true.&lt;/P&gt;
&lt;P&gt;In more readable form, your condition is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if
  x=5
  or (
    X=2 and W=3
  ) 
  or (
    X=2 and W=8 and Z=9
  )
then Ind_a=1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Oct 2021 08:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/AND-OR-conditions/m-p/775330#M246452</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-20T08:34:05Z</dc:date>
    </item>
  </channel>
</rss>

