<?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 DATES.... Using SAS date in proc sql &amp;quot;where&amp;quot; statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DATES-Using-SAS-date-in-proc-sql-quot-where-quot-statement/m-p/486751#M126701</link>
    <description>&lt;P&gt;I am passing&amp;nbsp;a date range&amp;nbsp;to a PROC SQL and attempting to use them in a where clause.&amp;nbsp; The query is against an Oracle database; the EFFECTIVEDATE comes in as date time format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I supply the dates from within the SAS code:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;%let Data_DT_MAX_EF= 18JUL2018;&lt;/FONT&gt; &lt;FONT color="#008000" face="Courier New" size="3"&gt;/*Used for testing*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;%let Data_DT_MIN_EF= 12JUL2018;&lt;/FONT&gt; &lt;FONT color="#008000" face="Courier New" size="3"&gt;/*Used for testing*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;And use them in the where clause:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;EFFECTIVEDATE &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;between&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Data_DT_MIN_EF &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Data_DT_MAX_EF&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;There are no errors.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;If I pass the dates from an EG program, the dates are passed between&amp;nbsp;EGP and SAS however&amp;nbsp;they are presented as numeric and the query fails.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.Research_Date;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; &lt;FONT face="Courier New" size="3"&gt;Data_DT_MIN_EF = intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'week1.5'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;Report_Date3,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'End'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; Data_DT_MAX_EF = intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'week1.5'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;Report_Date3,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'Begin'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _all_ &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;DATE9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_all_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)(=/); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; symput (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'Data_DT_MIN_EF'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Data_DT_MIN_EF);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; symput (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'Data_DT_MAX_EF'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Data_DT_MAX_EF);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: ORACLE prepare error: ORA-00932: inconsistent datatypes: expected DATE got NUMBER. SQL statement: SELECT TRANID,...&lt;/P&gt;&lt;P&gt;where&amp;nbsp; EFFECTIVEDATE between 21383 and 21377&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When and how is the best way to&amp;nbsp;format the date variables to make the where clause successful?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Aug 2018 16:40:31 GMT</pubDate>
    <dc:creator>RAW_newbie</dc:creator>
    <dc:date>2018-08-14T16:40:31Z</dc:date>
    <item>
      <title>DATES.... Using SAS date in proc sql "where" statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATES-Using-SAS-date-in-proc-sql-quot-where-quot-statement/m-p/486751#M126701</link>
      <description>&lt;P&gt;I am passing&amp;nbsp;a date range&amp;nbsp;to a PROC SQL and attempting to use them in a where clause.&amp;nbsp; The query is against an Oracle database; the EFFECTIVEDATE comes in as date time format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I supply the dates from within the SAS code:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;%let Data_DT_MAX_EF= 18JUL2018;&lt;/FONT&gt; &lt;FONT color="#008000" face="Courier New" size="3"&gt;/*Used for testing*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;%let Data_DT_MIN_EF= 12JUL2018;&lt;/FONT&gt; &lt;FONT color="#008000" face="Courier New" size="3"&gt;/*Used for testing*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;And use them in the where clause:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;EFFECTIVEDATE &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;between&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Data_DT_MIN_EF &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Data_DT_MAX_EF&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;There are no errors.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;If I pass the dates from an EG program, the dates are passed between&amp;nbsp;EGP and SAS however&amp;nbsp;they are presented as numeric and the query fails.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.Research_Date;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; &lt;FONT face="Courier New" size="3"&gt;Data_DT_MIN_EF = intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'week1.5'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;Report_Date3,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'End'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; Data_DT_MAX_EF = intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'week1.5'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;Report_Date3,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'Begin'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _all_ &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;DATE9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_all_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)(=/); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; symput (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'Data_DT_MIN_EF'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Data_DT_MIN_EF);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; symput (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'Data_DT_MAX_EF'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Data_DT_MAX_EF);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: ORACLE prepare error: ORA-00932: inconsistent datatypes: expected DATE got NUMBER. SQL statement: SELECT TRANID,...&lt;/P&gt;&lt;P&gt;where&amp;nbsp; EFFECTIVEDATE between 21383 and 21377&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When and how is the best way to&amp;nbsp;format the date variables to make the where clause successful?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 16:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATES-Using-SAS-date-in-proc-sql-quot-where-quot-statement/m-p/486751#M126701</guid>
      <dc:creator>RAW_newbie</dc:creator>
      <dc:date>2018-08-14T16:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: DATES.... Using SAS date in proc sql "where" statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATES-Using-SAS-date-in-proc-sql-quot-where-quot-statement/m-p/486762#M126705</link>
      <description>&lt;P&gt;Remember it needs to be valid SAS syntax and your code would resolve to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4" color="#800080"&gt;&lt;STRONG&gt;*What you have;&lt;/STRONG&gt;&lt;/FONT&gt;
EFFECTIVEDATE between &amp;amp;Data_DT_MIN_EF and &amp;amp;Data_DT_MAX_EF
&lt;FONT size="4" color="#800080"&gt;&lt;STRONG&gt;
*what sas sees;&lt;/STRONG&gt;&lt;/FONT&gt;
EFFECTIVEDATE between 12Jul2018 and 18Jul2018

&lt;FONT size="4" color="#800080"&gt;&lt;STRONG&gt;*valid SAS syntax;&lt;/STRONG&gt;&lt;/FONT&gt;
EFFECTIVEDATE between "&amp;amp;Data_DT_MIN_EF"d and "&amp;amp;Data_DT_MAX_EF"d&lt;/PRE&gt;
&lt;P&gt;If you're using SQL Pass through you'll need a different method, since they dates usually need to be formatted dd-mm-yy with single quotes or something like that. It varies slightly depending on the DB.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/152759"&gt;@RAW_newbie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am passing&amp;nbsp;a date range&amp;nbsp;to a PROC SQL and attempting to use them in a where clause.&amp;nbsp; The query is against an Oracle database; the EFFECTIVEDATE comes in as date time format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I supply the dates from within the SAS code:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;%let Data_DT_MAX_EF= 18JUL2018;&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#008000"&gt;/*Used for testing*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;%let Data_DT_MIN_EF= 12JUL2018;&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#008000"&gt;/*Used for testing*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;And use them in the where clause:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;EFFECTIVEDATE &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;between&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Data_DT_MIN_EF &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Data_DT_MAX_EF&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;There are no errors.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;If I pass the dates from an EG program, the dates are passed between&amp;nbsp;EGP and SAS however&amp;nbsp;they are presented as numeric and the query fails.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.Research_Date;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; &lt;FONT face="Courier New" size="3"&gt;Data_DT_MIN_EF = intnx(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'week1.5'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;Report_Date3,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'End'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; Data_DT_MAX_EF = intnx(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'week1.5'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;Report_Date3,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'Begin'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&amp;nbsp; format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _all_ &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;DATE9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&amp;nbsp; put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;_all_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)(=/); &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&amp;nbsp; call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; symput (&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'Data_DT_MIN_EF'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Data_DT_MIN_EF);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&amp;nbsp; call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; symput (&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'Data_DT_MAX_EF'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Data_DT_MAX_EF);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: ORACLE prepare error: ORA-00932: inconsistent datatypes: expected DATE got NUMBER. SQL statement: SELECT TRANID,...&lt;/P&gt;
&lt;P&gt;where&amp;nbsp; EFFECTIVEDATE between 21383 and 21377&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When and how is the best way to&amp;nbsp;format the date variables to make the where clause successful?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 17:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATES-Using-SAS-date-in-proc-sql-quot-where-quot-statement/m-p/486762#M126705</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-14T17:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: DATES.... Using SAS date in proc sql "where" statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATES-Using-SAS-date-in-proc-sql-quot-where-quot-statement/m-p/486863#M126738</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let Data_DT_MAX_EF= 18JUL2018; /*Used for testing*/
%let Data_DT_MIN_EF= 12JUL2018; /*Used for testing*/
And use them in the where clause:
EFFECTIVEDATE between &amp;amp;Data_DT_MIN_EF and &amp;amp;Data_DT_MAX_EF&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code would &lt;STRONG&gt;not&lt;/STRONG&gt; work in SAS or in Oracle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oracle needs (note the single quotes which are missing in the code above):&lt;/P&gt;
&lt;PRE&gt;EFFECTIVEDATE between '12JUL2018' and '18JUL2018'&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS&amp;nbsp;needs (single or double quotes are accepted in SAS, double quotes are better is macro variables are used):&lt;/P&gt;
&lt;PRE&gt;EFFECTIVEDATE between "12JUL2018"d and "18JUL2018"d&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 22:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATES-Using-SAS-date-in-proc-sql-quot-where-quot-statement/m-p/486863#M126738</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-14T22:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: DATES.... Using SAS date in proc sql "where" statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATES-Using-SAS-date-in-proc-sql-quot-where-quot-statement/m-p/487773#M127114</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;My failure was due to the formatting of the date being passed to the where clause.&amp;nbsp; Being new to converting dates I was missing the line in bold (middle of the 3 lines).&amp;nbsp; Currently a set of date intervals are developed within the EG program and passed to SAS base code with an "include" statement.&amp;nbsp; The same EGP loops through a dataset to supply a variable also supplied to the base code to produce 9 separate date dependent reports.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Data_DT_MIN_EF = intnx(&lt;FONT color="#800080"&gt;'week1.5'&lt;/FONT&gt;,&amp;amp;Report_Date1,-&lt;FONT color="#008080"&gt;1&lt;/FONT&gt;,&lt;FONT color="#800080"&gt;'End'&lt;/FONT&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Data_DT_MIN_EF2=put(Data_DT_MIN_EF,date9.);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;call symput ('Data_DT_MIN_EF', Data_DT_MIN_EF2);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The SAS base code now interprets the dates correctly in the "where" clause which uses the &lt;FONT face="Arial"&gt;EFFECTIVEDATE field within an Oracle table.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where clause:&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;EFFECTIVEDATE &lt;FONT color="#0000ff"&gt;between&lt;/FONT&gt; &lt;FONT color="#0000ff"&gt;%bquote&lt;/FONT&gt;('&amp;amp;Data_DT_MAX_EF') &lt;FONT color="#0000ff"&gt;and&lt;/FONT&gt; &lt;FONT color="#0000ff"&gt;%bquote&lt;/FONT&gt;('&amp;amp;Data_DT_MIN_EF')&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;Quotes are supplied within the statement above to comply with Oracle needs.&amp;nbsp; The dates without quotes as supplied by the EGP statement are used elsewhere in the reports.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 14:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATES-Using-SAS-date-in-proc-sql-quot-where-quot-statement/m-p/487773#M127114</guid>
      <dc:creator>RAW_newbie</dc:creator>
      <dc:date>2018-08-17T14:14:28Z</dc:date>
    </item>
  </channel>
</rss>

