Date: Wed, 23 Nov 2011 10:33:51 -0500
Reply-To: Tim Lash <tlash@KAHG.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Tim Lash <tlash@KAHG.COM>
Subject: Macro Quoting
I'm trying to dynamically construct the following segment of a DB2 where
clause in a SAS macro that will be invoked several times to cover different
time periods:
and a.REC_LD_DT >= '01/01/2007'
The decade and year values will be provided by separate macro variables.
I'm having difficulty composing the proper combination of %str and/or %quote
functions to accurately accomplish this. Here's my best attempt:
%let cY_PMO = %SYSFUNC(SUBSTR(&moy_str,1,1)) ;
%let wca = %quote(and a.REC_LD_DT >= %')
%let wcb = %quote(01/01/20) ;
%let wcc = %quote(%') ;
wc1 = &wca.&wcb. || &cDD.&cY_PMO. || &wcc. ;
I'm sure some combination of incorrect function, improper character escaping
and/or invalid concatenation is going on. The following errors are
generated along with the values (some containing non-printable characters)
of the _LOCAL_ variables that get PUT to the log file:
22: LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery
of the LINE and
COLUMN where the error has occurred.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted
string,
a numeric constant, a datetime constant, a missing value,
arrayname, (, +, -,
INPUT, NOT, PUT, ^, _NEW_, ~.
NOTE: Line generated by the invoked macro "AU_EP".
1 wc1 = &wca.&wcb. || &cDD.&cY_PMO. || &wcc. ;
-
200
NOTE: Line generated by the macro variable "WCB".
1 and a.REC_LD_DT >= '01/01/20
----------- --
388 200
AU_EP MOY_STR 706
AU_EP CDD 0
AU_EP CY_PMO 7
AU_EP WCA and a.REC_LD_DT >=
AU_EP WCB 01 01 20
AU_EP WCC
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR 388-185: Expecting an arithmetic operator.
NOTE: Numeric values have been converted to character values at the places
given by:
(Line):(Column).
0:-1 1:1 1:2
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference WC1 not resolved.
WARNING: Apparent symbolic reference WC1 not resolved.
WARNING: Apparent symbolic reference WC1 not resolved.
ERROR: CLI describe error: [IBM][CLI Driver][DB2/NT64] SQL0007N The
character "&" following
"GK = e.POLV_RT_CL_GK" is not valid. SQLSTATE=42601
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.57 seconds
cpu time 0.01 seconds
The errors certainly suggest a malformed string, yet I've not been able to
make much progress in crafting an accurate one. Any help would be greatly
appreciated.
Thanks,
Tim