<?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: Understand logic in where clause in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791588#M32614</link>
    <description>&lt;P&gt;The SAS log will show you how it interpreted the WHERE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;716  data check;
1717    set test;
1718    where (test1="No") ne (. ne test2&amp;lt;=2) ;
1719  run;

NOTE: There were 3 observations read from the data set WORK.TEST.
      WHERE (test1='No') not = ((test2 not = .) and (test2&amp;lt;=2));
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SAS will evaluate boolean expressions to 0 or 1.&amp;nbsp; &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;So testing if two boolean values are not equal is like doing an &lt;A href="https://en.wikipedia.org/wiki/Exclusive_or" target="_self"&gt;exclusive or&lt;/A&gt;.&amp;nbsp; (A or B but not both).&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now let's look at the meaning of this expression that SAS had decided the last clause means:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; ((test2 not = .) and (test2&amp;lt;=2))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS treats missing values as smaller than any actual numeric value.&amp;nbsp; There are 28 possible missing values. The regular missing value represented by a period in SAS code.&amp;nbsp; Plus special missing values ._&amp;nbsp; and .A thru .Z.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically that is true when TEST2 is smaller than 2 or has any special missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most likely they really didn't mean to include the special missings, but you would need to ask the author their intent.&lt;/P&gt;
&lt;P&gt;So if you want to exclude all of the missing values also:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(test2&amp;lt;=2 and not missing(test2))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be easier to code as one of these&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(.Z &amp;lt; test2 &amp;lt;=2)
(not (test2&amp;gt;2))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jan 2022 20:13:11 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-01-21T20:13:11Z</dc:date>
    <item>
      <title>Understand logic in where clause</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791507#M32605</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Could you please help me understand the logic of these 'where' clauses in SAS?&lt;/P&gt;
&lt;PRE&gt;proc print data=test;
where (test1="No") ne (. ne test2&amp;lt;=2);
run;

proc print data=test;
where (test1="No") ne (test2&amp;lt;=2);
run;&lt;/PRE&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791507#M32605</guid>
      <dc:creator>Abishekaa</dc:creator>
      <dc:date>2022-01-21T17:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Understand logic in where clause</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791510#M32606</link>
      <description>&lt;P&gt;You don't tell us what you want. We can only say that SAS is doing exactly what you told it to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will guess that you want either AND or OR instead of NE (but really, we should have to guess).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where (test1="No") and (test2&amp;lt;=2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where (test1="No") or (test2&amp;lt;=2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791510#M32606</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-21T17:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Understand logic in where clause</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791519#M32608</link>
      <description>&lt;P&gt;Hi Paige. Thank you! I couldn't wrap my head around the logic of using . and ne.&lt;/P&gt;
&lt;P&gt;Eg: what would be subset if you used the statement: where (. ne test&amp;lt;2)? Does it subset records only where 'test&amp;lt;2' or where 'test2' and missing data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791519#M32608</guid>
      <dc:creator>Abishekaa</dc:creator>
      <dc:date>2022-01-21T17:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Understand logic in where clause</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791521#M32609</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/102730"&gt;@Abishekaa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Paige. Thank you! I couldn't wrap my head around the logic of using . and ne.&lt;/P&gt;
&lt;P&gt;Eg: what would be subset if you used the statement: where (. ne test&amp;lt;2)? Does it subset records only where 'test&amp;lt;2' or where 'test2' and missing data?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;where (. ne test&amp;lt;2)&lt;/FONT&gt; tests to see if a missing value is not equal to (test&amp;lt;2) ,and &lt;FONT face="courier new,courier"&gt;test&amp;lt;2&lt;/FONT&gt; is either 0 if test&amp;gt;=2 and 1 if test&amp;lt;2. So the test is if the missing value is not equal to 0 or 1. I'm sure that's not what you are trying to do, and if it is what you are trying to do, more intuitive and less complicated code would probably work.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791521#M32609</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-21T17:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Understand logic in where clause</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791526#M32610</link>
      <description>&lt;P&gt;Thanks for explaining &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Could you please explain what would be the less complicated equivalent for these where clauses?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc print data=test;
where (test1="No") ne (. ne test2&amp;lt;=2);
run;

proc print data=test;
where (test1="No") ne (test2&amp;lt;=2);
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791526#M32610</guid>
      <dc:creator>Abishekaa</dc:creator>
      <dc:date>2022-01-21T17:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: Understand logic in where clause</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791536#M32612</link>
      <description>&lt;PRE&gt;where (test1="No") ne (. ne test2&amp;lt;=2);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two conditions:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="57px"&gt;&lt;BR /&gt;Test1=No&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="57px"&gt;. ne test2 &amp;lt;=2&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="57px"&gt;(test1="No") ne (. ne test2&amp;lt;=2)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT color="#FF9900"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT color="#FF9900"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT color="#FF9900"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT color="#FF9900"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT color="#FF9900"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;FONT color="#FF9900"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think we'd have to know more about the opposite values (ie the 0/0 conditions) to be able to simplify this logic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791536#M32612</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-21T17:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Understand logic in where clause</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791588#M32614</link>
      <description>&lt;P&gt;The SAS log will show you how it interpreted the WHERE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;716  data check;
1717    set test;
1718    where (test1="No") ne (. ne test2&amp;lt;=2) ;
1719  run;

NOTE: There were 3 observations read from the data set WORK.TEST.
      WHERE (test1='No') not = ((test2 not = .) and (test2&amp;lt;=2));
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SAS will evaluate boolean expressions to 0 or 1.&amp;nbsp; &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;So testing if two boolean values are not equal is like doing an &lt;A href="https://en.wikipedia.org/wiki/Exclusive_or" target="_self"&gt;exclusive or&lt;/A&gt;.&amp;nbsp; (A or B but not both).&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now let's look at the meaning of this expression that SAS had decided the last clause means:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; ((test2 not = .) and (test2&amp;lt;=2))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS treats missing values as smaller than any actual numeric value.&amp;nbsp; There are 28 possible missing values. The regular missing value represented by a period in SAS code.&amp;nbsp; Plus special missing values ._&amp;nbsp; and .A thru .Z.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically that is true when TEST2 is smaller than 2 or has any special missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most likely they really didn't mean to include the special missings, but you would need to ask the author their intent.&lt;/P&gt;
&lt;P&gt;So if you want to exclude all of the missing values also:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(test2&amp;lt;=2 and not missing(test2))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be easier to code as one of these&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(.Z &amp;lt; test2 &amp;lt;=2)
(not (test2&amp;gt;2))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 20:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Understand-logic-in-where-clause/m-p/791588#M32614</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-21T20:13:11Z</dc:date>
    </item>
  </channel>
</rss>

