<?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 function not working on date calculations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368208#M275444</link>
    <description>&lt;P&gt;What you probably wanted was&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where
  location_code not in ('101020' '101030' '101040' '151010' '151030' '501030')
  and work_queue not in ('L05' 'L20' 'L21' 'L22' 'L23')
  and bal &amp;gt; 500
  and cycles &amp;gt; 0
  and (hold_date + 2) &amp;lt; batch_date
  and (pending_hold_date + 2) &amp;lt; batch_date
  and (
    substr(mobile1,1,2) = '07'
    or substr(mobile2,1,2) = '07'
    or substr(mobile3,1,2) = '07'
  )
  and dob ne .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note how I use brackets and indentation to visualize the logic.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Jun 2017 09:26:30 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-06-19T09:26:30Z</dc:date>
    <item>
      <title>Where function not working on date calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368186#M275437</link>
      <description>&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;I'm trying to use a where statement on SAS 9.4 using two date variables but the code is not performing in the way I would expect it to.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;I want to retain only the obs where date1 + 2 is less than date2 using the code&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;date1 + &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="color: teal; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;2&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt; &amp;lt; date2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;but when I run the code, outputs include obs where date1 is higher than date2. I have also tried peforming the initial calculation in brackets in case that made any difference&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;(date1 + &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="color: teal; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;2)&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt; &amp;lt; date2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;but the outputs are still the same. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;If I put the same code in an if statement in the same data step it works fine. I realise I could just use this but I would like to understand why the where statement doesn't&amp;nbsp;work.&amp;nbsp;I've done quite a bit of searching online but can't find anything that might explain it so hoping someone might be able to point me in the right direction.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;Many thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 08:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368186#M275437</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2017-06-19T08:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not working on date calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368188#M275438</link>
      <description>&lt;P&gt;Please post example test data in the form of a datastep, you can get this by following this post:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then please show your code (just the relevant part) by posting it as text into a code window - which can be opened using the {i} above the post area.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 08:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368188#M275438</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-19T08:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not working on date calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368194#M275439</link>
      <description>&lt;P&gt;When you posted your question, you saw this below the posting window:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Stop right there!&lt;/STRONG&gt; Before pressing POST, tick off this checklist. Does your post …&lt;/P&gt;
&lt;TABLE align="left" border="1" cellpadding="5" cellspacing="5" width="75%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;✔ Have a descriptive subject line, i.e., How do I ‘XYZ’?&lt;/TD&gt;
&lt;TD&gt;✔ Use simple language and provide context? Definitely mention what version you’re on.&lt;/TD&gt;
&lt;TD&gt;✔ Include code and example data? Consider using the &lt;A href="https://communities.sas.com/t5/Community-Memo/Getting-the-Most-from-Your-Post-SAS-Syntax-Highlighter/ba-p/230172" target="_blank"&gt;SAS Syntax feature&lt;/A&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note the third section. "Code" is more than just a tiny snippet that does not even constitute one SAS statement.&lt;/P&gt;
&lt;P&gt;And add the log of the step, as it will contain pertinent information.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 08:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368194#M275439</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-19T08:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not working on date calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368199#M275440</link>
      <description>&lt;P&gt;Apologies, I had worked through the check lst and hoped what I'd provided would have been sufficient for someone to provide a view.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue I have is that this is a work based piece of code that accesses sensitive data so I am unable to provide the full data step and log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've edited both the data step and the log but hopefully the gist is still there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; testing;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ####;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; location_code not in (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'101020'&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'101030'&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'101040'&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'151010'&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'151030'&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'501030'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;and work_queue not in (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'L05'&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'L20'&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'L21'&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'L22'&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'L23'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;and bal &amp;gt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;500&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;and cycles &amp;gt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;and (hold_date + &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) &amp;lt; batch_date&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;and (pending_hold_date + &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) &amp;lt; batch_date&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;and substr(mobile1,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'07'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; or substr(mobile2,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'07'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; or substr(mobile3,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'07'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;and dob ne &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: There were 10674 observations read from the data set ####.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE (location_code not in ('101020', '101030', '101040', '151010', '151030',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '501030') and work_queue not in ('L05', 'L20',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'L21', 'L22', 'L23', 'L30', 'L31', 'P20', 'Q11', 'Q26', 'S28', 'S34', 'S36', 'S37', 'S38',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'S61') and (bal&amp;gt;500) and (cycles&amp;gt;0) and (batch_date&amp;gt;(hold_date+2)) and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (batch_date&amp;gt;(pending_hold_date+2)) and (SUBSTR(mobile1, 1, 2)='07')) or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (SUBSTR(mobile2, 1, 2)='07') or ((SUBSTR(mobile3, 1, 2)='07') and (dob not = .));&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.TESTING has 10674 observations and 13 variables.&lt;/P&gt;&lt;P&gt;NOTE: Compressing data set WORK.TESTING decreased size by 44.76 percent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Compressed is 116 pages; un-compressed would require 210 pages.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9.78 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.28 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;I've&amp;nbsp;attached an extract of the ouputs &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Thanks again&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13962i6B812F0E782772D6/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Sample data.PNG" title="Sample data.PNG" /&gt;</description>
      <pubDate>Mon, 19 Jun 2017 08:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368199#M275440</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2017-06-19T08:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not working on date calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368201#M275441</link>
      <description>&lt;P&gt;I abbreviated your code with your data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat pending_hold_date hold_date batch_date date9.;
format pending_hold_date hold_date batch_date date9.;
input pending_hold_date hold_date batch_date;
cards;
. 20-apr-17 29-apr-17
5-may-17 5-may-17 29-apr-17
4-jul-17 4-jul-17 29-apr-17
. 4-may-17 29-apr-17
6-may-17 29-apr-17 29-apr-17
;
run;

data want;
set have;
where
(hold_date + 2) &amp;lt; batch_date
and
(pending_hold_date + 2) &amp;lt; batch_date
;
run;

proc print data=want noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;According to the conditions, only obs 1 will be output.&lt;/P&gt;
&lt;P&gt;What output did you expect?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 09:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368201#M275441</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-19T09:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not working on date calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368204#M275442</link>
      <description>&lt;P&gt;Thanks Kurt and apologies again for my ignorance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data extract I'd attached&amp;nbsp;to my message was the outputs from the code so as per your response, what I was expecting was there would only be the 1 ob where the hold_date was 20-apr-17 and the batch_date was 29-apr-17, but my code is outputting all of those obs, including those that don't meet my criteria.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whilst I wouldn't consider my to be anywhere near an expert SAS programmer, I am reasonably competent and would have expected only those obs that meet all the criteria specified in the where statement to be returned in the output but wasn't sure if there was some sort of quirk that I wasn't aware of that means when you are combining character, numeric and date values (which I know are stored numerically) in the same where statement. then SAS may behave differently?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 09:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368204#M275442</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2017-06-19T09:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not working on date calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368206#M275443</link>
      <description>&lt;P&gt;It looks like the culprit is not the date comparison, but your use of and and or in the condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where
(
location_code not in ('101020' '101030' '101040' '151010' '151030' '501030')
and work_queue not in ('L05' 'L20' 'L21' 'L22' 'L23')
and bal &amp;gt; 500
and cycles &amp;gt; 0
and (hold_date + 2) &amp;lt; batch_date
and (pending_hold_date + 2) &amp;lt; batch_date
and substr(mobile1,1,2) = '07'
)
 or substr(mobile2,1,2) = '07' or
)
substr(mobile3,1,2) = '07'
and dob ne .
)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See where I added additional brackets that clarify where the "and before or" priority of boolean logic evaluation kicks in.&lt;/P&gt;
&lt;P&gt;So all observations that satisfy substr(mobile2,1,2) = '07' will be included. All other conditions are basically overridden by that.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 09:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368206#M275443</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-19T09:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not working on date calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368208#M275444</link>
      <description>&lt;P&gt;What you probably wanted was&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where
  location_code not in ('101020' '101030' '101040' '151010' '151030' '501030')
  and work_queue not in ('L05' 'L20' 'L21' 'L22' 'L23')
  and bal &amp;gt; 500
  and cycles &amp;gt; 0
  and (hold_date + 2) &amp;lt; batch_date
  and (pending_hold_date + 2) &amp;lt; batch_date
  and (
    substr(mobile1,1,2) = '07'
    or substr(mobile2,1,2) = '07'
    or substr(mobile3,1,2) = '07'
  )
  and dob ne .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note how I use brackets and indentation to visualize the logic.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 09:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368208#M275444</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-19T09:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Where function not working on date calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368211#M275445</link>
      <description>&lt;P&gt;That's fantastic, thanks Kurt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of those things where as soon as you read the solution, you fel like an idiot for not spotting it yourself!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 09:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-function-not-working-on-date-calculations/m-p/368211#M275445</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2017-06-19T09:35:15Z</dc:date>
    </item>
  </channel>
</rss>

