<?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: Comparing date values in where clause in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602924#M174620</link>
    <description>&lt;P&gt;Single quotes prevent all macro activity.&amp;nbsp; Begin by putting your references to macro variables in double quotes, then see if any problems remain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to show us a hard-coded (no macro language) version of a working program to get further advice.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Nov 2019 22:58:17 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-11-08T22:58:17Z</dc:date>
    <item>
      <title>Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602923#M174619</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the following query in Toad for Oracle and it works fine without issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT BASE.*, K.COL1, K.COL2&lt;BR /&gt;FROM MONTH_END_BASE BASE LEFT JOIN K_MASTER K&lt;BR /&gt;ON BASE.ACCOUNT_NUM=K.ACCOUNT_NUM AND BASE.SUBSCRIPTION=K.SUBSCRIPTION&lt;BR /&gt;WHERE EXTRACT (MONTH FROM KPI.ACTIVITY_DATE)=09 AND EXTRACT (YEAR FROM KPI.ACTIVITY_DATE)=2019 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In SAS I changed the query as below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;BR /&gt;CALL SYMPUT('MonthStart',TRIM(PUT(INTNX('MONTH',TODAY(),0,'B'),ddmmyys10.)));&lt;BR /&gt;CALL SYMPUT('MonthEnd',TRIM(PUT(INTNX('MONTH',TODAY(),0,'E'),ddmmyys10.)));&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;MonthStart.;&lt;BR /&gt;%PUT &amp;amp;MonthEnd.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CURRENT_MONTH_ACTIVITY AS&lt;BR /&gt;SELECT BASE.*, K.COL1, K.COL2&lt;BR /&gt;FROM MONTH_END_BASE BASE LEFT JOIN K_MASTER K&lt;BR /&gt;ON BASE.ACCOUNT_NUM=K.ACCOUNT_NUM AND BASE.SUBSCRIPTION=K.SUBSCRIPTION&lt;BR /&gt;WHERE K.ACTIVITY_DATE &amp;gt;= "&amp;amp;MonthStart." AND K.ACTIVITY_DATE &amp;lt;= "&amp;amp;MonthEnd." ;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting the error: &lt;STRONG&gt;Expressions&amp;nbsp;using equals (=) has&amp;nbsp;components&amp;nbsp;that are of&amp;nbsp;different data types&lt;/STRONG&gt; for all three conditions, that is, BASE.ACCOUNT_NUM=K.ACCOUNT_NUM, BASE.SUBSCRIPTION=K.SUBSCRIPTION and K.ACTIVITY_DATE&amp;gt;= "&amp;amp;MonthStart".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When this works in Toad, it means the datatypes are not the problem. But its not working in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Friday when I was trying this, the error message was only for the date comparison, so I thought I am doing something wrong with the SAS date format. But when I comment the where condition, the same error is thrown for the condition on "ON" as well. Not sure what the issue is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a newbie to SAS. Literally my first week with SAS programming. I still haven't got a hang of how SAS works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help with this issue is much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 18:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602923#M174619</guid>
      <dc:creator>sivaranjani</dc:creator>
      <dc:date>2019-11-10T18:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602924#M174620</link>
      <description>&lt;P&gt;Single quotes prevent all macro activity.&amp;nbsp; Begin by putting your references to macro variables in double quotes, then see if any problems remain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to show us a hard-coded (no macro language) version of a working program to get further advice.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2019 22:58:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602924#M174620</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-11-08T22:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602928#M174622</link>
      <description>&lt;P&gt;Double quotes didn't help. Also I tried with different date values as well (01Nov2019, 01/11/2019) and I tried the input function to change to different formats in where clause itself. For all the tries, I am getting the same error. No clue whats wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Activity Date column is of Date datatype in the table.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2019 23:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602928#M174622</guid>
      <dc:creator>sivaranjani</dc:creator>
      <dc:date>2019-11-08T23:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602930#M174623</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297867"&gt;@sivaranjani&lt;/a&gt;&amp;nbsp; &amp;nbsp;Why bother with a macro for a simple filter/*current month*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE CURRENT_MONTH_ACTIVITY AS
SELECT * FROM MONTH_END_BASE
WHERE put(ACTIVITY_DATE ,monyy7. -l)=put(today(),monyy7. -l);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Nov 2019 23:29:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602930#M174623</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-08T23:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602931#M174624</link>
      <description>&lt;P&gt;You have two issues, one is a the double quotes the second is invalid code or format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you're generating, assuming the macro does resolve correctly is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE CURRENT_MONTH_ACTIVITY AS
SELECT * FROM MONTH_END_BASE
WHERE ACTIVITY_DATE &amp;gt;= &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;"2019/10/01"&lt;/STRONG&gt;&lt;/FONT&gt; AND ACTIVITY_DATE &amp;lt;= &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;"2019/10/30"&lt;/FONT&gt; &lt;/STRONG&gt;;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That isn't valid SAS code. YOu need to pass dates either in the date9 format or no format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No format is easier but harder to read/debug, so use date9 to get your code working.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that I had to add a d to the end to indicate it's a date literal. Using the unformatted value saves those steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
CALL SYMPUT('MonthStart',TRIM(PUT(INTNX('MONTH',TODAY(),0,'B'), &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;date9.&lt;/STRONG&gt;&lt;/FONT&gt;)));
CALL SYMPUT('MonthEnd',TRIM(PUT(INTNX('MONTH',TODAY(),0,'E'), &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;date9.&lt;/STRONG&gt;&lt;/FONT&gt;)));
RUN;

%PUT &amp;amp;MonthStart.;
%PUT &amp;amp;MonthEnd.;


PROC SQL;
CREATE TABLE CURRENT_MONTH_ACTIVITY AS
SELECT * FROM MONTH_END_BASE
WHERE ACTIVITY_DATE &amp;gt;= &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;"&amp;amp;MonthStart."d&lt;/STRONG&gt; &lt;/FONT&gt;AND ACTIVITY_DATE &amp;lt;= &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;"&amp;amp;MonthEnd."d&lt;/STRONG&gt;&lt;/FONT&gt; ;
QUIT;

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297867"&gt;@sivaranjani&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to get the current month records from a table. Since this is going to be an automated monthly job, I can't give explicit values in where clause. So I am using the intnx function to get the month's start and end date. Then comparing them with the table value (date) in where clause. I tried different date formats but every time I am getting the same error: "ERROR: Expression using equals (=) has components that are of different data types."&lt;BR /&gt;&lt;BR /&gt;Below is my script. What am I doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA _NULL_;&lt;BR /&gt;CALL SYMPUT('MonthStart',TRIM(PUT(INTNX('MONTH',TODAY(),0,'B'),ddmmyys10.)));&lt;BR /&gt;CALL SYMPUT('MonthEnd',TRIM(PUT(INTNX('MONTH',TODAY(),0,'E'),ddmmyys10.)));&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;%PUT &amp;amp;MonthStart.;&lt;BR /&gt;%PUT &amp;amp;MonthEnd.;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CURRENT_MONTH_ACTIVITY AS&lt;BR /&gt;SELECT *&amp;nbsp;FROM MONTH_END_BASE&lt;BR /&gt;WHERE ACTIVITY_DATE &amp;gt;= '&amp;amp;MonthStart.' AND ACTIVITY_DATE &amp;lt;= '&amp;amp;MonthEnd.' ;&lt;BR /&gt;QUIT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2019 23:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602931#M174624</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-08T23:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602934#M174626</link>
      <description>&lt;P&gt;Thank you for your suggestion but it didn't work. I am still getting the same error &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2019 23:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602934#M174626</guid>
      <dc:creator>sivaranjani</dc:creator>
      <dc:date>2019-11-08T23:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602935#M174627</link>
      <description>&lt;P&gt;Thank you for your suggestion. I tried both your code snippets, with the date value hard-coded and also with the date9. format and date literal. I am still getting the same error. The datatype of Activity Date is "Date" and the values are as below&lt;BR /&gt;23/01/2018&lt;BR /&gt;24/01/2018&lt;BR /&gt;25/01/2018&lt;BR /&gt;24/01/2018&lt;BR /&gt;15/01/2018&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2019 23:49:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602935#M174627</guid>
      <dc:creator>sivaranjani</dc:creator>
      <dc:date>2019-11-08T23:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602944#M174629</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297867"&gt;@sivaranjani&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your suggestion. I tried both your code snippets, with the date value hard-coded and also with the date9. format and date literal. I am still getting the same error. The datatype of Activity Date is "Date" and the values are as below&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The code snippet as posted by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;works for me (see code below).&lt;/P&gt;
&lt;P&gt;If that's not working for you then please post the first error message you get in the SAS log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MONTH_END_BASE;
  input ACTIVITY_DATE :ddmmyy10.;
  format ACTIVITY_DATE ddmmyy10.;
  datalines;
23/01/2018
24/01/2018
25/01/2018
24/01/2018
15/01/2018
15/11/2019
;

DATA _NULL_;
  CALL SYMPUT('MonthStart',TRIM(PUT(INTNX('MONTH',TODAY(),0,'B'), date9.)));
  CALL SYMPUT('MonthEnd',TRIM(PUT(INTNX('MONTH',TODAY(),0,'E'), date9.)));
RUN;

%PUT &amp;amp;MonthStart.;
%PUT &amp;amp;MonthEnd.;

PROC SQL;
  CREATE TABLE CURRENT_MONTH_ACTIVITY AS
    SELECT * FROM MONTH_END_BASE
      WHERE ACTIVITY_DATE &amp;gt;= "&amp;amp;MonthStart."d AND ACTIVITY_DATE &amp;lt;= "&amp;amp;MonthEnd."d;
QUIT;

proc print data=CURRENT_MONTH_ACTIVITY;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 164px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33800iE16CACA2F6AC2B7A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 00:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602944#M174629</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-09T00:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602955#M174633</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297867"&gt;@sivaranjani&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your suggestion but it didn't work. I am still getting the same error &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS doesn't actually have a DATE type so can you post a proc contents on your month end base data set to show what the type and format? Type should be numeric with a format such as mmddy10&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 01:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/602955#M174633</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-09T01:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603067#M174700</link>
      <description>&lt;P&gt;I used the following query in Toad for Oracle and it works fine without issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT BASE.*, K.COL1, K.COL2&lt;BR /&gt;FROM MONTH_END_BASE BASE LEFT JOIN K_MASTER K&lt;BR /&gt;ON BASE.ACCOUNT_NUM=K.ACCOUNT_NUM AND BASE.SUBSCRIPTION=K.SUBSCRIPTION&lt;BR /&gt;WHERE EXTRACT (MONTH FROM KPI.ACTIVITY_DATE)=09 AND EXTRACT (YEAR FROM KPI.ACTIVITY_DATE)=2019 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In SAS I changed the query as below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;BR /&gt;CALL SYMPUT('MonthStart',TRIM(PUT(INTNX('MONTH',TODAY(),0,'B'),ddmmyys10.)));&lt;BR /&gt;CALL SYMPUT('MonthEnd',TRIM(PUT(INTNX('MONTH',TODAY(),0,'E'),ddmmyys10.)));&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;MonthStart.;&lt;BR /&gt;%PUT &amp;amp;MonthEnd.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CURRENT_MONTH_ACTIVITY AS&lt;BR /&gt;SELECT BASE.*, K.COL1, K.COL2&lt;BR /&gt;FROM MONTH_END_BASE BASE LEFT JOIN K_MASTER K&lt;BR /&gt;ON BASE.ACCOUNT_NUM=K.ACCOUNT_NUM AND BASE.SUBSCRIPTION=K.SUBSCRIPTION&lt;BR /&gt;WHERE K.ACTIVITY_DATE &amp;gt;= "&amp;amp;MonthStart." AND K.ACTIVITY_DATE &amp;lt;= "&amp;amp;MonthEnd." ;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting the error: &lt;STRONG&gt;Expressions&amp;nbsp;using equals (=) has&amp;nbsp;components&amp;nbsp;that are of&amp;nbsp;different data types&lt;/STRONG&gt; for all three conditions, that is, BASE.ACCOUNT_NUM=K.ACCOUNT_NUM, BASE.SUBSCRIPTION=K.SUBSCRIPTION and K.ACTIVITY_DATE&amp;gt;= "&amp;amp;MonthStart".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When this works in Toad, it means the datatypes are not the problem. But its not working in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Friday when I was trying this, the error message was only for the date comparison, so I thought I am doing something wrong with the SAS date format. But when I comment the where condition, the same error is thrown for the condition on "ON" as well. Not sure what the issue is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a newbie to SAS. Literally my first week with SAS programming. I still haven't got a hang of how SAS works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help with this issue is much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 18:07:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603067#M174700</guid>
      <dc:creator>sivaranjani</dc:creator>
      <dc:date>2019-11-10T18:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603070#M174703</link>
      <description>&lt;P&gt;If you're getting data from a database you likely have a datetime, not a date variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They need to be handled differently.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the following, which uses DATEPART() to convert the datetime to a date variable, which should work now.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS that you should try reading through.&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
CALL SYMPUT('MonthStart',TRIM(PUT(INTNX('MONTH',TODAY(),0,'B'), date9.)));
CALL SYMPUT('MonthEnd',TRIM(PUT(INTNX('MONTH',TODAY(),0,'E'), date9.)));
RUN;

%PUT &amp;amp;MonthStart.;
%PUT &amp;amp;MonthEnd.;


PROC SQL;
CREATE TABLE CURRENT_MONTH_ACTIVITY AS
SELECT * FROM MONTH_END_BASE
WHERE datepart(ACTIVITY_DATE) &amp;gt;= "&amp;amp;MonthStart."d AND datepart(ACTIVITY_DATE) &amp;lt;= "&amp;amp;MonthEnd."d ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297867"&gt;@sivaranjani&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I used the following query in Toad for Oracle and it works fine without issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SELECT BASE.*, K.COL1, K.COL2&lt;BR /&gt;FROM MONTH_END_BASE BASE LEFT JOIN K_MASTER K&lt;BR /&gt;ON BASE.ACCOUNT_NUM=K.ACCOUNT_NUM AND BASE.SUBSCRIPTION=K.SUBSCRIPTION&lt;BR /&gt;WHERE EXTRACT (MONTH FROM KPI.ACTIVITY_DATE)=09 AND EXTRACT (YEAR FROM KPI.ACTIVITY_DATE)=2019 ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS I changed the query as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA _NULL_;&lt;BR /&gt;CALL SYMPUT('MonthStart',TRIM(PUT(INTNX('MONTH',TODAY(),0,'B'),ddmmyys10.)));&lt;BR /&gt;CALL SYMPUT('MonthEnd',TRIM(PUT(INTNX('MONTH',TODAY(),0,'E'),ddmmyys10.)));&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;%PUT &amp;amp;MonthStart.;&lt;BR /&gt;%PUT &amp;amp;MonthEnd.;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CURRENT_MONTH_ACTIVITY AS&lt;BR /&gt;SELECT BASE.*, K.COL1, K.COL2&lt;BR /&gt;FROM MONTH_END_BASE BASE LEFT JOIN K_MASTER K&lt;BR /&gt;ON BASE.ACCOUNT_NUM=K.ACCOUNT_NUM AND BASE.SUBSCRIPTION=K.SUBSCRIPTION&lt;BR /&gt;WHERE K.ACTIVITY_DATE &amp;gt;= "&amp;amp;MonthStart." AND K.ACTIVITY_DATE &amp;lt;= "&amp;amp;MonthEnd." ;&lt;BR /&gt;QUIT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am getting the error: &lt;STRONG&gt;Expressions&amp;nbsp;using equals (=) has&amp;nbsp;components&amp;nbsp;that are of&amp;nbsp;different data types&lt;/STRONG&gt; for all three conditions, that is, BASE.ACCOUNT_NUM=K.ACCOUNT_NUM, BASE.SUBSCRIPTION=K.SUBSCRIPTION and K.ACTIVITY_DATE&amp;gt;= "&amp;amp;MonthStart".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When this works in Toad, it means the datatypes are not the problem. But its not working in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Friday when I was trying this, the error message was only for the date comparison, so I thought I am doing something wrong with the SAS date format. But when I comment the where condition, the same error is thrown for the condition on "ON" as well. Not sure what the issue is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am a newbie to SAS. Literally my first week with SAS programming. I still haven't got a hang of how SAS works.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help with this issue is much appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 21:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603070#M174703</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-10T21:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603071#M174704</link>
      <description>Are all these tables on the server? If you still get errors, you likely do have type mismatches and should run a PROC CONTENTS on each data set and post that information here for each variable in question.</description>
      <pubDate>Sun, 10 Nov 2019 21:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603071#M174704</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-10T21:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603079#M174706</link>
      <description>&lt;P&gt;You still seemed confused about what code you are asking SAS to run and what code you giving to Teradata to run.&lt;/P&gt;
&lt;P&gt;You should first try running the Teradata code that worked in the other tool.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
connect to teradata (....);
create table test1 as select * from connection to teradata
(select
  base.*
, k.col1
, k.col2
from month_end_base base
left join k_master k
  on base.account_num=k.account_num
 and base.subscription=k.subscription
where extract (month from kpi.activity_date)=09
  and extract (year from kpi.activity_date)=2019
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that works then try changing to the date range:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table test1 as select * from connection to teradata
(select
  base.*
, k.col1
, k.col2
from month_end_base base
left join k_master k
  on base.account_num=k.account_num
 and base.subscription=k.subscription
where  kpi.activity_date between date '2019-09-01' and date '2019-08-30'
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that works then make your macro variables have that EXACT same formatting.&amp;nbsp; YYMMDD10 formatted date values quotes with SINGLE quote characters.&amp;nbsp; You can add single quotes using the QUOTE() function by including the optional second argument.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('monthstart',quote(put(intnx('month',today(),0,'b'),yymmdd10.),"'");
  call symputx('monthend',quote(put(intnx('month',today(),0,'e'),yymmdd10.),"'");
run;

proc sql ;
connect to teradata (....);
create table test1 as select * from connection to teradata
(select
  base.*
, k.col1
, k.col2
from month_end_base base
left join k_master k
  on base.account_num=k.account_num
 and base.subscription=k.subscription
where  kpi.activity_date between date &amp;amp;monthstart. and date &amp;amp;monthend.
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your version of Teradata really wants date literals in that confusing day-month-year order that your SAS code was trying to use then use the DDMMYY format instead of the YYMMDD format in the PUT() function calls.&amp;nbsp; Or make your Teradata code more complex so that it can convert whatever string you do create in the macro variable into a value that will match the data type of the variable the the Teradata table.&amp;nbsp; Like you used the EXTRACT() function in your other Teradata code snippet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 21:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603079#M174706</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-10T21:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603080#M174707</link>
      <description>&lt;P&gt;The Oracle query as posted can't work because you're using alias &lt;EM&gt;KPI&lt;/EM&gt; in&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;KPI.ACTIVITY_DATE&lt;/EM&gt; but you've never defined this alias for a table. If you post code where you state it's working then try to post the actually tested code. ..but let's assume things would work if you'd use&amp;nbsp;K.ACTIVITY_DATE&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you're that new to SAS then we need to take a step-by-step approach to get to the bottom of things (plus you need to do SAS training! There is some free-of charge training available to give you a start).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If the different data types Error is the first one in your SAS log then that's exactly what it is: Within the SAS SQL the data types are different.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You're using one level table names in the Oracle SQL you've posted. That means the tables you're using are under the Oracle schema to which you've connected via Toad.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You're also using one level names in the SAS SQL. SAS has also a two level syntax: &amp;lt;libref&amp;gt;.&amp;lt;table name&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A libref is a logical name which points to the connection to be used for accessing a table. The connection itself gets defined via a SAS LIBNAME statement. If you omit the libref then SAS uses WORK as libref. This is a special library for a SAS session specific Work area on disk which gets created when you invoke a SAS session.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;What this means: The source tables used in your Oracle SQL are not the same than the ones used in the SAS SQL. There must be some prior processing which copies the Oracle tables into SAS WORK.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First steps:&lt;/P&gt;
&lt;P&gt;1. Please share the upstream code which creates the tables in SAS Work (as this doesn't happen automatically)&lt;/P&gt;
&lt;P&gt;2. Please share the upstream code which loads the tables from Oracle into SAS (that's eventually the same code bit like under 1 )&lt;/P&gt;
&lt;P&gt;3. Execute the following code and share the result with us:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=MONTH_END_BASE;
run;
proc contents data=K_MASTER;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 22:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603080#M174707</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-10T22:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603106#M174714</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thank you for your help. Please find the code and the proc content details below.&lt;/P&gt;&lt;P&gt;Also, thank you for suggesting the SAS course. I am doing an online SAS course.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;BR /&gt;CALL SYMPUT('MonthPartition',TRIM(PUT(INTNX('MONTH',TODAY(),-1,'B'),yymmn6.)));&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;MonthPartition.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE lib.MONTH_END_BASE AS&lt;BR /&gt;SELECT *&lt;BR /&gt;FROM DB.MI_MONTH_END_BASE_&amp;amp;MonthPartition;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;BR /&gt;CALL SYMPUT('MonthStart',TRIM(PUT(INTNX('MONTH',TODAY(),0,'B'),ddmmyy10.)));&lt;BR /&gt;CALL SYMPUT('MonthEnd',TRIM(PUT(INTNX('MONTH',TODAY(),0,'E'),ddmmyy10.)));&lt;/P&gt;&lt;P&gt;/* CALL SYMPUT('MonthStart',TRIM(PUT(INTNX('MONTH',TODAY(),0,'B'), date9.)));*/&lt;BR /&gt;/* CALL SYMPUT('MonthEnd',TRIM(PUT(INTNX('MONTH',TODAY(),0,'E'), date9.)));*/&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;MonthStart.;&lt;BR /&gt;%PUT &amp;amp;MonthEnd.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE lib.K_MASTER AS&lt;BR /&gt;SELECT *&amp;nbsp;FROM DB.DAILY_K_MASTER;&lt;/P&gt;&lt;P&gt;QUIT;&lt;BR /&gt;&lt;BR /&gt;PROC CONTENTS DATA=lib.MONTH_END_BASE;&lt;BR /&gt;RUN;&lt;BR /&gt;PROC CONTENTS DATA=lib.K_MASTER;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CURRENT_MONTH_ACTIVITY AS&lt;BR /&gt;SELECT B.*, M.*&lt;BR /&gt;FROM lib.MONTH_END_BASE B&lt;BR /&gt;LEFT JOIN lib.K_MASTER M&lt;BR /&gt;ON B.ACCOUNT_NUM=M.ACCOUNT_NUM and B.SUBSCRIBER_NO=M.SUBSCRIBER_NO;&lt;BR /&gt;WHERE ACTIVITY_DATE&amp;gt;="&amp;amp;MonthStart." and ACTIVITY_DATE&amp;lt;="&amp;amp;MonthEnd.";&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 01:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603106#M174714</guid>
      <dc:creator>sivaranjani</dc:creator>
      <dc:date>2019-11-11T01:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603113#M174715</link>
      <description>&lt;P&gt;So ACTIVITY_DATE does NOT have DATE values. It has DATETIME values.&amp;nbsp; So you want to compare to DATETIME values (number of seconds since 1960) and not a DATE values (number of days since 1960).&lt;/P&gt;
&lt;P&gt;If you want to use a macro variable to hold DATETIME values then either leave it with the raw number of seconds since 1960 and don't add the quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CALL SYMPUTX('MonthStart',INTNX('DTMONTH',DATETIME(),0,'B'));
...
WHERE ACTIVITY_DATE&amp;gt;=&amp;amp;MonthStart. ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or generate it in a format that the DATETIME informat can read and add the quotes &lt;STRONG&gt;and the dt suffix.&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CALL SYMPUTX('MonthStart',put(INTNX('DTMONTH',DATETIME(),0,'B')),datetime20.);
...
WHERE ACTIVITY_DATE&amp;gt;="&amp;amp;MonthStart."dt ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A couple of other things. Don't use the old CALL SYMPUT() instead of the newer CALL SYMPUTX() unless you really need to store leading and/or trailing spaces into the macro variable.&lt;/P&gt;
&lt;P&gt;Speaking of leading spaces why does one of your variables appear to have a leading space in the photograph of the output of proc contents?&amp;nbsp; Is that really a space? Is it an underscore that is just blending into the border lines? If it really is a leading space then you will need to use a name literal to reference that variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;' ACCOUNT_NUM'n&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 03:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603113#M174715</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-11T03:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing date values in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603115#M174716</link>
      <description>&lt;P&gt;Given that you're comfortable using Toad to write and test Oracle syntax it's at current stage may be easier for you to use the exactly same Oracle syntax also within a SAS program (=you can copy/paste the syntax from Toad to SAS).&lt;/P&gt;
&lt;P&gt;Using SQL this way is called Explicit pass-through SQL in SAS documentation. Explicit SQL gets sent by SAS without any changes directly to the database for execution.&lt;/P&gt;
&lt;P&gt;In below code the explicit pass-through SQL is within the brackets of the ...from connection to (&amp;lt;explicit Oracle SQL&amp;gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS Macro code gets pre-processed and though you can still use SAS Macros in explicit pass-through SQL. The SAS macro variables get resolved before SAS sends the SQL to the database.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I couldn't test it but below should work based on all the code you've already shared with us. It assumes that libref DB points to the Oracle database.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('monthpartition',put(intnx('month',today(),-1,'b'),yymmn6.));
  call symputx('monthstart',cats("'",put(intnx('month',today(),0,'b'),yymmdd10.),"'"));
  call symputx('monthstartPlus1',cats("'",put(intnx('month',today(),1,'b'),yymmdd10.),"'"));
  stop;
run;
%put &amp;amp;=monthpartition;
%put &amp;amp;=monthstart;
%put &amp;amp;=monthstartPlus1;

proc sql;
  connect using db as ora;
  create table current_month_activity as
  select * from connection to ora
  (
    SELECT BASE.*, K.COL1, K.COL2
    FROM 
      MI_MONTH_END_BASE_&amp;amp;MonthPartition BASE 
      LEFT JOIN 
      K_MASTER K
        ON BASE.ACCOUNT_NUM=K.ACCOUNT_NUM AND BASE.SUBSCRIPTION=K.SUBSCRIPTION
           and K.ACTIVITY_DATE &amp;gt;= date &amp;amp;monthstart and K.ACTIVITY_DATE &amp;lt; date &amp;amp;monthstartPlus1
  )
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The word doc you've posted shows that the data types for the same named variables in the two SAS tables are different. Based on the code you've shared I don't really understand how this could happen and further investigation would be necessary (like: What are the data types in the Oracle tables). But let's park this for now and try making the explicit pass-through approach working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should this not work:&lt;/P&gt;
&lt;P&gt;Copy the explicit-pass through bit into a text editor, replace the macro variables 1:1 to what they resolve to (=what the %put statements print into the SAS log as values) and then execute the code in Toad. Debug the code in Toad, copy/paste the fully working code back into SAS and replace the fixed strings with the macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 12:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-date-values-in-where-clause/m-p/603115#M174716</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-11T12:05:46Z</dc:date>
    </item>
  </channel>
</rss>

