<?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: Using a macro in a where statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183865#M303439</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;==&amp;nbsp; DCL_SYS_YMD is a date field ==&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Also seen this by SAS as data-type I assume, not only being a DB2 definition&lt;BR /&gt;Then use the d (date) modifier behind those strings "2014-05-01"d&amp;nbsp;&amp;nbsp;&amp;nbsp; "2014-06-30"d&amp;nbsp; as SAS will convert them to SAS-dates in those cases (not being strings).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For better performance look at the sqlconstdatetime option &lt;A href="http://support.sas.com/documentation/cdl/en/sqlproc/63043/HTML/default/viewer.htm#n1mar4dz971ln3n1lxmgx7hcgyc0.htm" title="http://support.sas.com/documentation/cdl/en/sqlproc/63043/HTML/default/viewer.htm#n1mar4dz971ln3n1lxmgx7hcgyc0.htm"&gt;SAS(R) 9.3 SQL Procedure User's Guide&lt;/A&gt;&lt;BR /&gt;To follow what is happening think about using sastrace option &lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/65247/HTML/default/viewer.htm#n0732u1mr57ycrn1urf24gzo38sc.htm" title="http://support.sas.com/documentation/cdl/en/acreldb/65247/HTML/default/viewer.htm#n0732u1mr57ycrn1urf24gzo38sc.htm"&gt;SAS/ACCESS(R) 9.3 for Relational Databases: Reference, Second Edition&lt;/A&gt; It will show you what is happening when translating SAS-ansi SQL to native SQL statements&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 04 Jun 2014 10:32:00 GMT</pubDate>
    <dc:creator>jakarman</dc:creator>
    <dc:date>2014-06-04T10:32:00Z</dc:date>
    <item>
      <title>Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183855#M303429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Aloha,&lt;/P&gt;&lt;P&gt;I am new to this community and have a question.&lt;/P&gt;&lt;P&gt;I am trying to update a current SAS program to automate it as much as possible.&lt;/P&gt;&lt;P&gt;This program extracts data based on selected time periods.&lt;/P&gt;&lt;P&gt;Rather than having to open the program and updating the dates I would like to be able to have it run and automatically determined the "BEGIN" and "END" periods.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Current code (modifiied)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LET BDATE = '2014-05-01';&amp;nbsp; /* Sets the beginning of the extract as the first day of the previous month */&lt;/P&gt;&lt;P&gt;%LET EDATE = '2014-06-30';&amp;nbsp; /* Sets the ending of the extract as the last day of the current month */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CONNECT TO ODBC(DSN=DB0P UID=&amp;amp;dssuid PWD=&amp;amp;dsspwd);&lt;/P&gt;&lt;P&gt;&amp;nbsp; CREATE TABLE DATA1 AS SELECT *&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM CONNECTION TO ODBC&lt;/P&gt;&lt;P&gt;&amp;nbsp; (SELECT &lt;/P&gt;&lt;P&gt;&amp;nbsp; DCL_SYS_YMD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS ENTRY_DT,&lt;/P&gt;&lt;P&gt;&amp;nbsp; DCL_PROC_YMD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS SERV_DT,&lt;/P&gt;&lt;P&gt;&amp;nbsp; DCL_PROV1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS PROVIDER,&lt;/P&gt;&lt;P&gt;&amp;nbsp; DCL_RSN_CODE1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS RVW_RSN1,&lt;/P&gt;&lt;P&gt;&amp;nbsp; DCL_RSN_CODE2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS RVW_RSN2&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM GETME.DRCLAIMS&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHERE&amp;nbsp; DCL_SYS_YMD BETWEEN &amp;amp;BDATE AND &amp;amp;EDATE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; );&lt;/P&gt;&lt;P&gt;&amp;nbsp; %PUT &amp;amp;SQLXMSG;&lt;/P&gt;&lt;P&gt;&amp;nbsp; DISCONNECT FROM ODBC;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried using :&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; BPRD = intnx('month',today(),-1,'b');&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; EPRD = intnx('month',today(),0,'e');&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; BPR = put(&amp;amp;BPRD,DATE9.);&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; EPR = put(&amp;amp;EPRD,DATE9.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and modified my where statement to&lt;/P&gt;&lt;P&gt; WHERE&amp;nbsp; DCL_SYS_YMD BETWEEN &amp;amp;BPR AND &amp;amp;EPR&lt;/P&gt;&lt;P&gt;I get the following error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;ERROR: CLI describe error: [IBM][CLI Driver][DB2] SQL0104N&amp;nbsp; An unexpected token ")" was found following ")".&amp;nbsp; Expected&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tokens may include:&amp;nbsp; "NEXTVAL CURRVAL".&amp;nbsp; SQLSTATE=42601&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;5079&amp;nbsp;&amp;nbsp;&amp;nbsp; %PUT &amp;amp;SQLXMSG;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;[IBM][CLI Driver][DB2] SQL0104N&amp;nbsp; An unexpected token ")" was found following ")".&amp;nbsp; Expected tokens may include:&amp;nbsp; "NEXTVAL&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;CURRVAL".&amp;nbsp; SQLSTATE=42601&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I have tried different ways but cannot get it to recognize the dates, any assistance would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mahalo, Jim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 00:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183855#M303429</guid>
      <dc:creator>KimoMakano</dc:creator>
      <dc:date>2014-06-04T00:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183856#M303430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DATA _NULL_;&lt;/P&gt;&lt;P&gt;CALL SYMPUT ("BPRD",INTNX('MONTH',TODAY(),-1,'B'));&amp;nbsp; &lt;/P&gt;&lt;P&gt;CALL SYMPUT ("EPRD",INTNX('MONTH',TODAY(),0,'E'));&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%PUT BPRD = &amp;amp;BPRD. EPRD = &amp;amp;EPRD.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can learn more about the CALL SYMPUT routine at &lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000210266.htm" title="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000210266.htm"&gt;SAS(R) 9.2 Macro Language: Reference&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 01:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183856#M303430</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2014-06-04T01:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183857#M303431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mahalo Scott,&lt;/P&gt;&lt;P&gt;When I try that I get this error.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;ERROR: CLI describe error: [IBM][CLI Driver][DB2] SQL0401N&amp;nbsp; The data types of the operands for the operation "" are not compatible or comparable.&amp;nbsp; SQLSTATE=42818 8304&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;%PUT &amp;amp;SQLXMSG;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;[IBM][CLI Driver][DB2] SQL0401N&amp;nbsp; The data types of the operands for the operation "" are not compatible or comparable.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;SQLSTATE=42818&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 02:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183857#M303431</guid>
      <dc:creator>KimoMakano</dc:creator>
      <dc:date>2014-06-04T02:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183858#M303432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alternately, use the %Sysfunc() macro function in a %Let statement to permit use of non macro functions such as INTNX().&amp;nbsp; Note that the macro language is essentially a text language so wuoting of constants is not required - cf month, b and e below.&amp;nbsp; Also, you need to use putn() or putc() with %Sysfunc - I have added quotes and a trailing D to convert BPR and EPR to SAS date literals (which do require quotes - double in this instance to allow macro resolution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Richard&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; BPRD = %Sysfunc(intnx(month, %Sysfunc(today()),-1,b));&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; EPRD = %Sysfunc(intnx(month, %Sysfunc(today()),0,e));&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; BPR = "%Sysfunc(putn(&amp;amp;BPRD,DATE9))"D;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; EPR = "%Sysfunc(putn(&amp;amp;EPRD,DATE9))"D;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 02:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183858#M303432</guid>
      <dc:creator>RichardinOz</dc:creator>
      <dc:date>2014-06-04T02:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183859#M303433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Firstly you don't have a macro variable called &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;amp;BDATE&lt;/SPAN&gt; or &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;amp;EDATE.&amp;nbsp; So you need to create these.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Secondly the error suggests to me that you are attempting to compare a character value with a numeric variable.&amp;nbsp; You need to ensure that you are comparing like data types.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 03:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183859#M303433</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2014-06-04T03:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183860#M303434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The macro-vars bdate and edate are created first but defined as strings.&lt;BR /&gt;The SAS environment is having well defined conventions for date time and datatime.&amp;nbsp; DB2 is not using those conventions, but having his own.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the SQL you&amp;nbsp; are coding: "WHERE&amp;nbsp; DCL_SYS_YMD BETWEEN &amp;amp;BDATE AND &amp;amp;EDATE"&lt;/P&gt;&lt;P&gt;The definition of DCL_SYS_YMD is not clear is it char or numeric how is it converted between DB2 ODBC into SAS vice versa.&lt;/P&gt;&lt;P&gt;A string (character) using a between is not really logical. &lt;BR /&gt;That is the first action you should do, investigate in researching of the datatypes and conversions.&lt;/P&gt;&lt;P&gt;When you have the types in SAS been converted to date-processing (validated DCL_SYS_YMD) you can proceed to SQL coding.&lt;BR /&gt;For the more standardizing you could thing of a standard macro setting al those kind of needed date references.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 07:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183860#M303434</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-06-04T07:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183861#M303435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mahalo Scott,&lt;/P&gt;&lt;P&gt;I created them via&lt;/P&gt;&lt;P&gt;%LET BDATE = '2014-05-01';&amp;nbsp; /* Sets the beginning of the extract as the first day of the previous month */&lt;/P&gt;&lt;P&gt;%LET EDATE = '2014-06-30';&amp;nbsp; /* Sets the ending of the extract as the last day of the current month */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the PROC SQL statement it reads these and works well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 08:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183861#M303435</guid>
      <dc:creator>KimoMakano</dc:creator>
      <dc:date>2014-06-04T08:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183862#M303436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mahalo Jaap,&lt;/P&gt;&lt;P&gt;DCL_SYS_YMD is a date field.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 08:49:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183862#M303436</guid>
      <dc:creator>KimoMakano</dc:creator>
      <dc:date>2014-06-04T08:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183863#M303437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So you need to change &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;DATA _NULL_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;CALL SYMPUT ("BPRD",INTNX('MONTH',TODAY(),-1,'B')); &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;CALL SYMPUT ("EPRD",INTNX('MONTH',TODAY(),0,'E'));&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;to &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;/P&gt;&lt;P&gt;CALL SYMPUTX ("BDATE",QUOTE(PUT(INTNX('MONTH',TODAY(),-1,'B'),YYMMDDD10.)));&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;CALL SYMPUTX ("EDATE",QUOTE(PUT(INTNX('MONTH',TODAY(),0,'E'),YYMMDDD10.)));&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;BDATE. &amp;amp;EDATE.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This produces "2014-05-01" "2014-06-30", which replicate what you have been entering manually.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 09:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183863#M303437</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2014-06-04T09:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183864#M303438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You cannot use the SAS functions INTNX() or PUT() inside of the SQL code that you are manually passing to ODBC (unless perhaps your ODBC connection is to a SAS server).&lt;/P&gt;&lt;P&gt;It looks like your foreign database liked it when you used quoted strings that looked like 'YYYY-MM-DD' so you need to use those types of values in your generated code.&lt;/P&gt;&lt;P&gt;Since you are doing this in macro world you need to use %SYSFUNC() and remove the quotes around the character arguments to INTNX().&lt;/P&gt;&lt;P&gt;You can use the DEQUOTE() function as a easy trick to get the values inside of single quotes instead of double quotes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: blue;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black;"&gt; BPRD = %sysfunc(dequote("'%sysfunc(intnx(month,%sysfunc(today()),-1,b),yymmdd10.)'"));&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: blue;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black;"&gt; EPRD = %sysfunc(dequote("'%sysfunc(intnx(month,%sysfunc(today()),0,e),yymmdd10.)'")); &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 10:15:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183864#M303438</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-06-04T10:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183865#M303439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;==&amp;nbsp; DCL_SYS_YMD is a date field ==&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Also seen this by SAS as data-type I assume, not only being a DB2 definition&lt;BR /&gt;Then use the d (date) modifier behind those strings "2014-05-01"d&amp;nbsp;&amp;nbsp;&amp;nbsp; "2014-06-30"d&amp;nbsp; as SAS will convert them to SAS-dates in those cases (not being strings).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For better performance look at the sqlconstdatetime option &lt;A href="http://support.sas.com/documentation/cdl/en/sqlproc/63043/HTML/default/viewer.htm#n1mar4dz971ln3n1lxmgx7hcgyc0.htm" title="http://support.sas.com/documentation/cdl/en/sqlproc/63043/HTML/default/viewer.htm#n1mar4dz971ln3n1lxmgx7hcgyc0.htm"&gt;SAS(R) 9.3 SQL Procedure User's Guide&lt;/A&gt;&lt;BR /&gt;To follow what is happening think about using sastrace option &lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/65247/HTML/default/viewer.htm#n0732u1mr57ycrn1urf24gzo38sc.htm" title="http://support.sas.com/documentation/cdl/en/acreldb/65247/HTML/default/viewer.htm#n0732u1mr57ycrn1urf24gzo38sc.htm"&gt;SAS/ACCESS(R) 9.3 for Relational Databases: Reference, Second Edition&lt;/A&gt; It will show you what is happening when translating SAS-ansi SQL to native SQL statements&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 10:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183865#M303439</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-06-04T10:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro in a where statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183866#M303440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Many mahalos Tom,&lt;/P&gt;&lt;P&gt;This worked!!&lt;/P&gt;&lt;P&gt;I am very greatful for your support, this is just what I needed.&lt;/P&gt;&lt;P&gt;Mahalos to all for your assistance.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jun 2014 17:18:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-in-a-where-statement/m-p/183866#M303440</guid>
      <dc:creator>KimoMakano</dc:creator>
      <dc:date>2014-06-04T17:18:15Z</dc:date>
    </item>
  </channel>
</rss>

