<?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 Condition not working as expected in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313432#M68110</link>
    <description>I am confused here. I have observation "XYZ" with value "P" populated. My condition says give all records where tes1 and test2 should not be null, which is true with the observation 'XYZ'?</description>
    <pubDate>Tue, 22 Nov 2016 12:01:20 GMT</pubDate>
    <dc:creator>KiranMaddi</dc:creator>
    <dc:date>2016-11-22T12:01:20Z</dc:date>
    <item>
      <title>WHERE Condition not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313420#M68104</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have some test data below and I would like to have columns with both the Test columns not being null/blank. I have tried below and doesn't seem to be working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Name = 'ABC'; 
Test1 = ' ';
Test2 = ' ';output;
Name = 'XYZ'; 
Test1  = ' '; 
Test2 = 'P';output;
run;

Data want;
Set have;
WHERE Test1 NE ' ' and Test2 NE ' ';
RUN;

/* Also tried*/
Data want;
Set have;
WHERE (Test1 NE ' ' and Test2 NE ' ');
RUN;

/* Also tried*/

Data want;
Set have;
WHERE (Test1 NE ' ' )and (Test2 NE ' ');
RUN;

/* Also tried*/

PROC SQL;
Create table want as select * from have where WHERE Test1 NE ' ' and Test2 NE ' ';
QUIT;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But strangely "OR" seems to be working. I am not sure what I am doing wrong here. Please can some one point me to the right direction?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Working*/

Data want;
Set have;
WHERE (Test1 NE ' ' or Test2 NE ' ');
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2016 11:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313420#M68104</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-11-22T11:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE Condition not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313424#M68106</link>
      <description>&lt;P&gt;Since you have no observation where your condition is fulfilled, you won't get any output.&lt;/P&gt;
&lt;P&gt;Add an observation that meets your criteria:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Name = 'ABC'; 
Test1 = ' ';
Test2 = ' ';output;
Name = 'DEF'; 
Test1 = 'x';
Test2 = 'y';output;
Name = 'XYZ'; 
Test1  = ' '; 
Test2 = 'P';output;
run;

Data want;
Set have;
WHERE Test1 NE ' ' and Test2 NE ' ';
RUN;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Name    Test1    Test2

DEF       x        y  
&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2016 11:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313424#M68106</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-22T11:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE Condition not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313425#M68107</link>
      <description>&lt;P&gt;When you use the AND operator, you want both conditions to be true to output, which is not true in any case here, since NE = Not Equals &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 11:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313425#M68107</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-22T11:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE Condition not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313428#M68108</link>
      <description>&lt;P&gt;Now, if your intention was to scan for observations where one of the test variables is not blank, then, per de Morgan's law:&lt;/P&gt;
&lt;P&gt;not (A and B) = not A or not B&lt;/P&gt;
&lt;P&gt;your OR condition is the one to use.&lt;/P&gt;
&lt;P&gt;(A is for "test1 = ' '", B is for "test2 = ' '")&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 11:48:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313428#M68108</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-22T11:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE Condition not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313432#M68110</link>
      <description>I am confused here. I have observation "XYZ" with value "P" populated. My condition says give all records where tes1 and test2 should not be null, which is true with the observation 'XYZ'?</description>
      <pubDate>Tue, 22 Nov 2016 12:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313432#M68110</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-11-22T12:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE Condition not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313436#M68111</link>
      <description>I guess the condition is true for 'XYZ'.</description>
      <pubDate>Tue, 22 Nov 2016 12:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313436#M68111</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-11-22T12:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE Condition not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313439#M68112</link>
      <description>&lt;P&gt;No &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; It is not true for observation 'XYZ'. Test1 is empty, but Test2 is not. Therefore the condition is not true.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 12:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313439#M68112</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-22T12:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE Condition not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313440#M68113</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37160"&gt;@KiranMaddi&lt;/a&gt; wrote:&lt;BR /&gt;I am confused here. I have observation "XYZ" with value "P" populated. My condition says give all records where tes1 and test2 should not be null, which is true with the observation 'XYZ'?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No. Your condition asks for&lt;/P&gt;
&lt;P&gt;(test1 is not null) AND (test2 is not null)&lt;/P&gt;
&lt;P&gt;So both have to be populated.&lt;/P&gt;
&lt;P&gt;If you wanted for (everyday logic notation)&lt;/P&gt;
&lt;P&gt;(test1 or test2) to be not null,&lt;/P&gt;
&lt;P&gt;you have to write&lt;/P&gt;
&lt;P&gt;test1 ne ' ' or test2 ne ' ';&lt;/P&gt;
&lt;P&gt;!!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 12:12:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313440#M68113</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-22T12:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE Condition not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313447#M68115</link>
      <description>&lt;P&gt;Your wording of the problem ("both the Test columns not being null/blank") is a bit ambiguous to me.&amp;nbsp; It could&amp;nbsp; mean that you want each of the TEST columns to be non-blank.&amp;nbsp;&amp;nbsp; But I think you want records in&amp;nbsp;TEST1,TEST2&amp;nbsp;are not both null.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is so, then this expression might be more intuitively obvious:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; where not(test1=' ' and test2=' ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or you could use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where cmiss(test1,test2)&amp;lt;2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;CMISS function counts missing character values.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 13:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313447#M68115</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-22T13:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE Condition not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313459#M68118</link>
      <description>Thanks mkeintz&lt;BR /&gt;&lt;BR /&gt;This works like a treat. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Nov 2016 13:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-Condition-not-working-as-expected/m-p/313459#M68118</guid>
      <dc:creator>KiranMaddi</dc:creator>
      <dc:date>2016-11-22T13:20:48Z</dc:date>
    </item>
  </channel>
</rss>

