LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 2 Aug 2006 11:44:17 -0400
Reply-To:     Talbot Michael Katz <topkatz@MSN.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Talbot Michael Katz <topkatz@MSN.COM>
Subject:      I am too darn stupid to ever figure out macro quoting

Okay, I'm pulling my already-thinning hair out here.

I want to use a where clause to pull certain observations to print, based on the appearance of a substring in a text field, so I want to use something like

(where = (dba_nm like '%ESSO%'))

but the substring (ESSO in the example above) is in a macro variable, and you can't do

(where = (dba_nm like '%&sstr.%'))

or even

(where = (dba_nm like "%&sstr.%"))

The following test program did exactly what I wanted (SAS 9.1.3, Windows XP):

title2 "test_where_quote_1.sas" ; %let pstr = GF ; data tWq1 ; length cv $4. ; input nv cv ; iv + 1 ; cards ; 1 AGFD 1 POUY 1 FGJ 2 QWE 2 AGFD 3 OIUE 4 AGFD 5 ITY 5 ASDG 5 AGFD ; run ; title3 "local print twq1 (where = (cv like %quote(%str (%'%%)%str(&pstr.)%str(%%%'))))" ; proc print data = twq1 (where = (cv like % str(%'%%)%str(&pstr.)%str(%%%'))) ; run ; title3 ;

giving the following output:

The SAS System 11:19 Wednesday, August 2, 2006 1 test_where_quote_1.sas local print twq1 (where = (cv like '%GF%'))

Obs cv nv iv

1 AGFD 1 1 5 AGFD 2 5 7 AGFD 4 7 10 AGFD 5 10

So I figured I was ready to run with my real data, sitting on a UNIX box, running SAS 8.2. Here's my print statement:

rsubmit ; title3 "&remote. print gblr.le_&ledsn1._s (where = (dba_nm like %quote(%str(%'%%)%str(&dba_nm_str.)%str(%%%'))))" ; endrsubmit ; rsubmit ; proc print data = gblr.le_&ledsn1._s (where = (dba_nm like %str(%'%%)%str(&dba_nm_str.)%str(%%%'))) ; run ; endrsubmit ;

Here's the log:

176 rsubmit ; NOTE: Remote submit to CS10000 commencing. 65 title3 "&remote. print gblr.le_&ledsn1._s (where = (dba_nm like 65 ! %quote(%str(%'%%)%str(&dba_nm_str.)%str(%%%'))))" ; NOTE: Remote submit to CS10000 complete. 177 178 rsubmit ; NOTE: Remote submit to CS10000 commencing. 66 proc print data = gblr.le_&ledsn1._s (where = (dba_nm like 66 ! %str(%'%%)%str(&dba_nm_str.)%str(%%%'))) ; NOTE 139-205: Line generated by the macro function "STR". 66 '% - 22 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, (, +, -, INPUT, NOT, PUT, ^, ~.

NOTE: Line generated by the macro function "STR". 66 '% - 76 ERROR 76-322: Syntax error, statement will be ignored.

ERROR: Syntax error while parsing WHERE clause. 67 run ;

NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE PRINT used: real time 0.06 seconds cpu time 0.04 seconds

NOTE: Remote submit to CS10000 complete.

What's going on?

-- TMK -- "The Macro Klutz"


Back to: Top of message | Previous page | Main SAS-L page