<?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: Handling multiple conditions in WHERE clause in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612431#M18556</link>
    <description>Yes, your understanding is correct on my requirement. I do have test data&lt;BR /&gt;at the moment to test your code. Couple of questions though.&lt;BR /&gt;&lt;BR /&gt;What if the REPORTING_METHOD values contains either 'ACS' or 'OCS'? Will&lt;BR /&gt;your code still works?&lt;BR /&gt;&lt;BR /&gt;If I ask you write the condition without reversing the logic, Is itn't a&lt;BR /&gt;matter of replacing AND with OR and vice-versa and removing NOT?&lt;BR /&gt;</description>
    <pubDate>Tue, 17 Dec 2019 15:32:49 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2019-12-17T15:32:49Z</dc:date>
    <item>
      <title>Handling multiple conditions in WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612319#M18551</link>
      <description>&lt;P&gt;I have multiple extract transformations in my SAS DI Job and all those extract transformations has the following condition under 'where' tab&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;VALID_FROM_DTTM &amp;lt;= DATETIME () AND VALID_TO_DTTM &amp;gt;=DATETIME ()
&amp;amp; 
REPORTING_METHOD = "&amp;amp;REPORTINGMETHOD" 
&amp;amp;
REPORTING_DT = &amp;amp;REPORTINGDATE
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now I was asked to add the one more condition based on REPORTING_METHOD. If REPORTING_METHOD is "ACS" then I have to add the condition like&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;put(INITIAL_RECOGNITION_DT,yymmn6.) &amp;lt;= put(REPORTING_DT,yymmn6.)&amp;nbsp;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If REPORTING_METHOD is "OCS" then I have to add the condition like&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;put(INITIAL_RECOGNITION_DT,yymmn6.) &amp;gt;= put(REPORTING_DT,yymmn6.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It means I have to write a code to conditionally change the filter condition which I'm not certain how to handle it in Extract transformation.&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;VALID_FROM_DTTM &amp;lt;= DATETIME () AND VALID_TO_DTTM &amp;gt;=DATETIME ()
&amp;amp; 
REPORTING_METHOD = "&amp;amp;REPORTINGMETHOD" 
&amp;amp;
REPORTING_DT = &amp;amp;REPORTINGDATE
&amp;amp;
put(INITIAL_RECOGNITION_DT,yymmn6.) &amp;lt;= put(REPORTING_DT,yymmn6.) /*if REPORTING_METHOD  is "ACS" */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appericiate if someone of you guide me here.&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>Tue, 17 Dec 2019 07:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612319#M18551</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-12-17T07:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Handling multiple conditions in WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612329#M18552</link>
      <description>&lt;P&gt;As I understand it, you MUST test&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;INITIAL_RECOGNITION_DT&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;yymmn6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;REPORTING_DT&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;yymmn6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;REPORTING_METHOD="ACS"but&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but you don't need to filter on INITIAL_RECOGNITION_DT otherwise.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, I believe you could use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(REPORTING_METHOD^="ACS"  or  put(INITIAL_RECOGNITION_DT,yymmn6.) &amp;lt;= put(REPORTING_DT,yymmn6.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW, since initial_recognition_dt and reporting_dt are date variables, when you want to determine whether they are in different months, you don't need a pair of PUT functions.&amp;nbsp; Instead you can use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intck('month',initial_recognition_dt,reportig_dt)&amp;gt;0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the intnx function above tells how many month boundaries are crossed between the dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 08:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612329#M18552</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-12-17T08:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Handling multiple conditions in WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612334#M18553</link>
      <description>&lt;P&gt;I can't understand your Guidelines. What I want is to check for the REPORTING_METHOD value. If it equals "ACS" then I want to add the below condition along with other condition as mentioned in Initial post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(INITIAL_RECOGNITION_DT,yymmn6.) &amp;lt;= put(REPORTING_DT,yymmn6.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it equals "OCS" then I want to add the below condition&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(INITIAL_RECOGNITION_DT,yymmn6.) &amp;gt;= put(REPORTING_DT,yymmn6.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 08:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612334#M18553</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-12-17T08:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: Handling multiple conditions in WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612415#M18554</link>
      <description>&lt;P&gt;Please re-read my note:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which includes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;
&lt;DIV id="messagebodydisplay_0_0" class="lia-message-body lia-component-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;If so, I believe you could use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(REPORTING_METHOD^="ACS"  or  put(INITIAL_RECOGNITION_DT,yymmn6.) &amp;lt;= put(REPORTING_DT,yymmn6.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I added that a comment on the second condition, i.e.&lt;/P&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;
&lt;DIV id="messagebodydisplay_0_0" class="lia-message-body lia-component-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;   ..... put(INITIAL_RECOGNITION_DT,yymmn6.) &amp;lt;= put(REPORTING_DT,yymmn6.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where I suggested making it more compact by using the INTNX function, as in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intck('month',initial_recognition_dt,reportig_dt)&amp;gt;0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;
&lt;DIV id="messagebodydisplay_0_0" class="lia-message-body lia-component-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 17 Dec 2019 14:46:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612415#M18554</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-12-17T14:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Handling multiple conditions in WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612417#M18555</link>
      <description>&lt;P&gt;What exactly are you having trouble with? Also why are you sometimes spelling out the AND operator and sometimes using &amp;amp; as the AND operator?&amp;nbsp; That will just cause you confusion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To add those conditions it will probably be easier to reverse the logic a little. So when REPORTING_METHOD is ACS you want to reject the values where recognition date is after the reporting date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where VALID_FROM_DTTM &amp;lt;= DATETIME()
  and VALID_TO_DTTM &amp;gt;= DATETIME()
  and REPORTING_METHOD = "&amp;amp;REPORTINGMETHOD" 
  and REPORTING_DT = &amp;amp;REPORTINGDATE
  and not (REPORTING_METHOD="ACS" AND put(INITIAL_RECOGNITION_DT,yymmn6.) &amp;gt; put(REPORTING_DT,yymmn6.))
  and not (REPORTING_METHOD="OCS" AND put(INITIAL_RECOGNITION_DT,yymmn6.) &amp;lt; put(REPORTING_DT,yymmn6.))
;&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, 17 Dec 2019 15:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612417#M18555</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-17T15:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Handling multiple conditions in WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612431#M18556</link>
      <description>Yes, your understanding is correct on my requirement. I do have test data&lt;BR /&gt;at the moment to test your code. Couple of questions though.&lt;BR /&gt;&lt;BR /&gt;What if the REPORTING_METHOD values contains either 'ACS' or 'OCS'? Will&lt;BR /&gt;your code still works?&lt;BR /&gt;&lt;BR /&gt;If I ask you write the condition without reversing the logic, Is itn't a&lt;BR /&gt;matter of replacing AND with OR and vice-versa and removing NOT?&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Dec 2019 15:32:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612431#M18556</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-12-17T15:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: Handling multiple conditions in WHERE clause</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612456#M18557</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;If I ask you write the condition without reversing the logic, Is itn't a matter of replacing AND with OR and vice-versa and removing NOT?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The form I posted was NOT (A and B).&amp;nbsp; So make yourself a little truth table and work it out for yourself.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;A | B | A and B | not (A and B) 
--|---|---------|--------------
Y | Y | Y       | N
Y | N | N       | Y
N | Y | N       | Y
N | N | N       | Y
&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;What if the REPORTING_METHOD values contains either 'ACS' or 'OCS'? Will&lt;BR /&gt;your code still works?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Depends on what you mean by contains.&amp;nbsp; The test is whether the value is exactly ACS or OCS.&amp;nbsp; It it is neither of those exact value then the equality test fails so the result of the date test will not matter.&amp;nbsp; So for any values other than exactly ACS or OCS the date order does not matter as this NOT (A and B) test will be true because the A part is false.&amp;nbsp; &amp;nbsp;Added another (AND 1=1) to a list of boolean expressions being ADDed together does not change the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 16:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Handling-multiple-conditions-in-WHERE-clause/m-p/612456#M18557</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-17T16:57:40Z</dc:date>
    </item>
  </channel>
</rss>

