<?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: Finding the non-matching the records based on some condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595413#M171278</link>
    <description>How do you tackle this if I ask you to write the condition in WHERE instead&lt;BR /&gt;of IF?&lt;BR /&gt;</description>
    <pubDate>Thu, 10 Oct 2019 14:22:32 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2019-10-10T14:22:32Z</dc:date>
    <item>
      <title>Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595355#M171246</link>
      <description>&lt;P&gt;Assuming I'm creating a dataset based on WHERE clause. It means only the data which passed the condition will be filtered and inserted into the dataset which we create. Is there a way to capture the non-matching records in one dataset which doesn't statisfy the condition mentioned in WHERE clause?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;e.g. If there are 10 records in HAVE dataset and we're getting only 5 records in WANT dataset due to the WHERE clause and the other&amp;nbsp;5 records was excluded. I want to capture excluded records in other dataset EXCLUDED.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 12:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595355#M171246</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-10-10T12:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595360#M171248</link>
      <description>&lt;P&gt;Use a simple condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data
  want
  fail
;
set have;
if condition
then output want;
else output fail;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2019 12:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595360#M171248</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-10T12:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595367#M171252</link>
      <description>Any other ways?&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Oct 2019 13:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595367#M171252</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-10-10T13:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595375#M171258</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Any other ways?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sure, but not as simple, so don't waste your time.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 13:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595375#M171258</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-10T13:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595413#M171278</link>
      <description>How do you tackle this if I ask you to write the condition in WHERE instead&lt;BR /&gt;of IF?&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Oct 2019 14:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595413#M171278</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-10-10T14:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595420#M171283</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How do you tackle this if I ask you to write the condition in WHERE instead&lt;BR /&gt;of IF?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Basically you don't.&lt;/P&gt;
&lt;P&gt;The WHERE is applied to the input vector.&amp;nbsp; Anything that does not match is excluded and cannot be manipulated in that data step.&lt;/P&gt;
&lt;P&gt;You would have to use a second data step with a where clause that is basically the NOT of the one you are using.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 14:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595420#M171283</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-10T14:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595424#M171286</link>
      <description>Could you please help me with one example?&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Oct 2019 14:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595424#M171286</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-10-10T14:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595476#M171323</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Could you please help me with one example?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you mean of two data steps:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   where value in ('a' 'b' 'c');
run;

data want2;
   set have;
   where not (value in ('a' 'b' 'c'));
run;&lt;/PRE&gt;
&lt;P&gt;The NOT operation negates the logical value of the expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 16:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595476#M171323</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-10T16:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595624#M171393</link>
      <description>&lt;P&gt;It works with one condition and I'm unable to mame it work for more than one condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following code is working correctly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set sashelp.class;
   where not (age in (11,12,13));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where as the below code is not working if I tweak the above code with more than one condition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;6         data want2;
27            set sashelp.class;
28            where not (age in (11,12,13)
29         and weight=112);
30         run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
      WHERE age not in (11, 12, 13) or (weight not = 112);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
   set sashelp.class;
   where not (age in (11,12,13)
and weight=112);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&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, 11 Oct 2019 04:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595624#M171393</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-10-11T04:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595628#M171395</link>
      <description>&lt;P&gt;You need to negate the&amp;nbsp;&lt;EM&gt;whole&lt;/EM&gt; condition. Enclose everything in an additional pair of brackets, and put the not before that.&lt;/P&gt;
&lt;P&gt;Or apply de Morgan's laws.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 04:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595628#M171395</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-11T04:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595636#M171399</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even though using the WHERE statement in a SAS data step is syntactically correct, you won't find a lot of experienced SAS users coding this way.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 05:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595636#M171399</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-10-11T05:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595644#M171402</link>
      <description>&lt;P&gt;I tried as syou suggested but it still seem to be not working. Not sure why second condition is resolving it as OR instead of AND&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         data want2;
27            set sashelp.class;
28            where not ((age in (11,12,13)
29         and weight=112));
30         run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
      WHERE age not in (11, 12, 13) or (weight not = 112);
NOTE: The data set WORK.WANT2 has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Oct 2019 06:33:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595644#M171402</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-10-11T06:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595649#M171404</link>
      <description>&lt;P&gt;SAS automatically applies De Morgan's law when it finds a completely negated condition.&lt;/P&gt;
&lt;PRE&gt;not (a and b)&lt;/PRE&gt;
&lt;P&gt;is equal to&lt;/P&gt;
&lt;PRE&gt;(not a) or (not b)&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Oct 2019 06:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595649#M171404</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-11T06:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595652#M171405</link>
      <description>&lt;P&gt;then may I know how to make it work?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 07:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595652#M171405</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-10-11T07:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595680#M171417</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;then may I know how to make it work?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It DOES work.&lt;/P&gt;
&lt;P&gt;See this example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
set sashelp.class;
where age in (11,12,13) and weight=128;
run;

data want2;
set sashelp.class;
where not (age in (11,12,13) and weight=128);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(I had to change the weight value, so that the first condition selects at least one observation)&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt; 73         data want1;
 74         set sashelp.class;
 75         where age in (11,12,13) and weight=128;
 76         run;
 
 NOTE: There were 1 observations read from the data set SASHELP.CLASS.
       WHERE age in (11, 12, 13) and (weight=128);
 NOTE: The data set WORK.WANT1 has 1 observations and 5 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 77         
 78         data want2;
 79         set sashelp.class;
 80         where not (age in (11,12,13) and weight=128);
 81         run;
 
 NOTE: There were 18 observations read from the data set SASHELP.CLASS.
       WHERE age not in (11, 12, 13) or (weight not = 128);
 NOTE: The data set WORK.WANT2 has 18 observations and 5 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.02 seconds
       cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;18 + 1 gives 19, the number of observations in sashelp.class.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 11:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595680#M171417</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-11T11:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595947#M171527</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;In this situation, using WHERE instead of IF (as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has offered) doesn't win you much. But it can be done in a single step. One way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data inc exl ;                                                                                                                          
  set sashelp.class (where=(sex eq "M") in=inc)                                                                                         
      sashelp.class (where=(sex ne "M"))                                                                                                
  ;                                                                                                                                     
  if inc then output inc ;                                                                                                              
  else        output exl ;                                                                                                              
run ;  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data inc exl ;                                                                                                                          
  do until (z_inc) ;                                                                                                                    
    set sashelp.class (where=(sex eq "M")) end = z_inc ;                                                                                
    output inc ;                                                                                                                        
  end ;                                                                                                                                 
  do until (z_exc) ;                                                                                                                    
    set sashelp.class (where=(sex ne "M")) end = z_exc ;                                                                                
    output exl ;                                                                                                                        
  end ;                                                                                                                                 
run ;    
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I wouldn't recommend either because in both cases you end up reading all input records into the buffer, which defies the purpose of using WHERE vs IF in the first place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Oct 2019 05:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595947#M171527</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-12T05:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the non-matching the records based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595948#M171528</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;Mind that all solutions relying on WHERE involve multiple reads of the input dataset and need considerably more code than the simple if, so they are inefficient both in use of computing resources and programmer's time.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Oct 2019 08:32:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-non-matching-the-records-based-on-some-condition/m-p/595948#M171528</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-12T08:32:31Z</dc:date>
    </item>
  </channel>
</rss>

