<?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: Where = Data Step option not behaving as expected in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622125#M182986</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;ALWAYS look at your log&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290130"&gt;@petergomillion&lt;/a&gt;: Also known as Maxim 2 (see link "Maxims of Maximally Efficient SAS Programmers"). There is a &lt;STRONG&gt;VERY BIG REASON&lt;/STRONG&gt; why this maxim is ranked so high up on the list.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Feb 2020 06:52:31 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-02-04T06:52:31Z</dc:date>
    <item>
      <title>Where = Data Step option not behaving as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622106#M182973</link>
      <description>&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have an exercise where (no pun intended) I need to keep the observations for the variable Country that is equal to "US" or 'us'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm tired but I don't see why this code is not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= "/folders/myfolders/cert/input/input27.sas7bdat" out=results_output27a
(where=(Country ne 'AU' OR 'au'));
by state descending Postal_code; 
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried this code above with single quotes and double-quotes. When I run this code what do I see...AU in my results! I was fuming.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eventually, I found a workaround by choosing a data set statement where. Where the state is missing. That worked but I want to know why the above code did not work. According to the documentation, it should work.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 04:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622106#M182973</guid>
      <dc:creator>petergomillion</dc:creator>
      <dc:date>2020-02-04T04:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Where = Data Step option not behaving as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622109#M182975</link>
      <description>&lt;P&gt;The expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE=(country ne 'AU' or 'au');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is parsed as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; WHERE=( (country ne 'AU')&amp;nbsp; or 'au');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The expression after the 'or'&amp;nbsp;&amp;nbsp; is non-zero (non-blank in this case), and therefore interpreted as true.&amp;nbsp; So you should have in your log (ALWAYS look at your log) the note&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt; WHERE 1 /* an obviously TRUE WHERE clause */ ;&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an example please run:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.class (where=(sex ne 'F' or 'M'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Consider doing this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= "/folders/myfolders/cert/input/input27.sas7bdat" out=results_output27a
(where=(Country not in ('AU','au')));
by state descending Postal_code; 
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 04:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622109#M182975</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-04T04:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Where = Data Step option not behaving as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622110#M182976</link>
      <description>&lt;P&gt;According to the rules of operator precedence, expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Country ne 'AU' OR 'au'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is evaluated as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Country ne 'AU') OR 'au'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The expression in parenthesis returns either 0 or 1, which SAS tries to combine with "au", which, since it isn't missing ("&amp;nbsp; ") is considered true (1), hence the result is always true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Country ne 'AU' AND Country ne 'au'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Country in ("US", "us")&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 04:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622110#M182976</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-02-04T04:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Where = Data Step option not behaving as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622111#M182977</link>
      <description>&lt;P&gt;Have your tried giving the variable name for each conditions like below,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where=(country ^= 'AU' OR country ^= 'au');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 05:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622111#M182977</guid>
      <dc:creator>Jebastin</dc:creator>
      <dc:date>2020-02-04T05:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: Where = Data Step option not behaving as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622123#M182984</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where=(strip(lowcase(country)) = 'au')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;Better use a libname to access the dataset for clean code.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 08:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622123#M182984</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2020-02-05T08:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Where = Data Step option not behaving as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622125#M182986</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;ALWAYS look at your log&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290130"&gt;@petergomillion&lt;/a&gt;: Also known as Maxim 2 (see link "Maxims of Maximally Efficient SAS Programmers"). There is a &lt;STRONG&gt;VERY BIG REASON&lt;/STRONG&gt; why this maxim is ranked so high up on the list.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 06:52:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622125#M182986</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-04T06:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: Where = Data Step option not behaving as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622190#M183016</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/300475"&gt;@Jebastin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Have your tried giving the variable name for each conditions like below,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where=(country ^= 'AU' OR country ^= 'au');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With an OR, that would always be true.&amp;nbsp; You could do that with an AND.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 14:27:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622190#M183016</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-02-04T14:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Where = Data Step option not behaving as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622240#M183034</link>
      <description>&lt;P&gt;What about Au or aU?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where=( upcase(country) ne 'AU' )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 16:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622240#M183034</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-04T16:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: Where = Data Step option not behaving as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622306#M183048</link>
      <description>&lt;P&gt;Those combinations of cases were not in the data set.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 21:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622306#M183048</guid>
      <dc:creator>petergomillion</dc:creator>
      <dc:date>2020-02-04T21:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Where = Data Step option not behaving as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622376#M183080</link>
      <description>&lt;P&gt;That's correct&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 08:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-Data-Step-option-not-behaving-as-expected/m-p/622376#M183080</guid>
      <dc:creator>Jebastin</dc:creator>
      <dc:date>2020-02-05T08:18:52Z</dc:date>
    </item>
  </channel>
</rss>

