Resolving Macro Variables in quotes within PROC SQL Pass-throughs

Other topics

Remarks:

More information on the %BQUOTE function can be found here: https://v8doc.sas.com/sashtml/macro/z4bquote.htm

Pass-through with Macro Variable that is a Date

First, I will place my date into a Macro Variable.

NOTE: I find that date9. works great with IBM® Netezza® SQL and Transact-SQL. Use whichever format that works for the type of SQL you're executing.

data _null_;
            call symput('testDate',COMPRESS(put(today(),date9.)));
;RUN;
%PUT &testDate;

My %PUT statement resolves to: 10MAR2017

Next, I want to run a PROC SQL Pass-through and resolve that Macro Variable inside to specify a date.

PROC SQL;
CONNECT TO odbc AS alias (dsn=myServer user=userName password= pass);
CREATE TABLE TableName AS 
SELECT * 
FROM connection to alias
    (
        SELECT *
        FROM
            Database.schema.MyTable
        WHERE
            DateColumn = %bquote('&testDate')
    );
QUIT;

%bquote('&testDate') will resolve to '10MAR2017' when the code executes.

Contributors

Topic Id: 9396

Example Ids: 29111

This site is not affiliated with any of the contributors.