Date: Mon, 7 Jan 2002 10:02:42 -0500
Reply-To: Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject: Re: SASTRAP: Macro Quoteing Functions
Content-Type: text/plain; charset="iso-8859-1"
Huck,
The problem is a question of how the macro facility returns tokens to the
word scanner for the compiler. In some cases one token say AB gets sent as
two tokens A and B. (For example,
%let x = A ;
%let y = z ;
%let z = B ;
&x&&&y
This does not cause a problem, but one can imagine that when parts have to
come together correctly from different levels there is room for an error. I
do not think quoting must be involved but it is the easiest way to create
the problem. Here is a similar example
43 %macro mac (x=a,y=b);
44 data _null_ ;
45 v = %str(%')&x&y%str(%') ;
46 put v= ;
47 run ;
48 %mend mac ;
49 %mac()
MPRINT(MAC): data _null_ ;
NOTE: Line generated by the invoked macro "MAC".
1 data _null_ ; v = '&x&y' ; put v= ; run ;
-
388
ERROR 388-185: Expecting an arithmetic operator.
NOTE: Line generated by the invoked macro "MAC".
1 data _null_ ; v = '&x&y' ; put v= ; run ;
-
76
ERROR 76-322: Syntax error, statement will be ignored.
-
386
--
202
MPRINT(MAC): v = 'ab' ;
MPRINT(MAC): put v= ;
MPRINT(MAC): run ;
ERROR 386-185: Expecting an arithmetic expression.
ERROR 202-322: The option or parameter is not recognized and will be
ignored.
)
The mprint shows the tokens juxtaposed so the code looks correct but is has
been parsed by the compiler as separate pieces and hence incorrect syntax.
IanWhitlock@westat.com
-----Original Message-----
From: Huck [mailto:huck@SKIPTHISFINN.COM]
Sent: Saturday, January 05, 2002 1:08 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: SASTRAP: Macro Quoteing Functions
and just what kind of person is it that posts replies to their own postings
again?
i spent hours the first time i ran into this kind of problem before trying
the obvious: "%unquote"
my beef is that it looks fine in the log, and in this case if i was
expecting upper case inside the
quotes, the solution isnt as easy to see. the first time it was upper case,
and i checked every bit
of code that built the variable, put the quotes on, passed it along, printed
out debugging stuff
everywhere, and all i kept seeing was my properly quoted string in the log,
finally i %unquote'ed
the variable just as it went to the parser, and the problem went away, it
happened again, a few
times, before i finaly learned.
i now know what to look for now, "the error makes no sense when compared to
whats in the log". When
that happens the first thing to remember is %unquote.
what got me into trouble this time? a macro routine sortof like.
%macro utl1(&_fid)
%local _part;
%do %while(0 eq %sysfunc(fget(&_fid,_part,200)));
%do;%superq(_part)%end;
%end;
%mend;
%let &_vn=%utl1(&_fid);
this utility reads parms from files, and of couse must totaly work in macro
quoteing to allow users
to put special characters into the files. when i forgot to unquote the
string being passed to
FILENAME, i got into trouble. i tell the parent routine, the one calling
utl1, which parms dont need
quoteing, in this case i forgot to mention the one about to be used in the
filename statement.
my thanks to the "macro maven" for the %do;%end; without any spaces,
that solution evaded me for years, and is critical to that solution.
On Sat, 05 Jan 2002 05:33:07 GMT, ... some self-replying fool ......
huck@skipthisfinn.com (Huck)
wrote:
>MPRINT(INBRDES2): RUN;
>ERROR: Error in the LIBNAME or FILENAME statement.
>MPRINT(MKDRLIST): FILENAME XLATE '/USERS/TEST/NDC.TXT';
the above LOOKS LIKE a perfectly valid filename statment,
it could have an invalid filename, but it is a correct stmt.
one time it was an assignment with this problem, such as a='SOME STRING';
and it wanted an operator between some and string (along with a list of
other errors).
....
i now know what to look for now, "the error makes no sense at all when
compared to whats in
the log". When that happens the first thing to try is %unquote. save your
self the hours of head
scratching...... it doenst have to be the quote character, percent signs,
and ampersands
are escaped, maybe equals signs and some other operators, certain words like
and/or ...
if you ever called a quoteing function in this run try %unquote first ...
what can it hurt?