Date: Sun, 10 Jul 2005 00:07:27 +0000
Reply-To: iw1junk@COMCAST.NET
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <iw1junk@COMCAST.NET>
Subject: Re: Comment in a macro - puzzling
Gordon,
Perhaps it is time to warn you of a well kept secret that there
are two macro languages - one is compiled between %MACRO and
%MEND statements, and the other is an open code language.
In open code
* %let a=45;
%put &a;
the * begins a comment ending with the semi-colon, so the
variable A is not defined. In
%macro q ;
* %let a=45;
%put &a;
%mend q ;
the macro compiler sees two macro statements (instructions), %LET
and %PUT. What about the *? That is constant text, i.e. it is
not a macro instruction, but rather SAS code that will be passed
to the SAS compiler. Consequently the same code performs
differently in the two different language settings.
Here is pure macro example.
%let rem = x = y ;
%let &rem ;
In open code these two statements result in the creation of two
global macro variables REM and X. When placed in a macro the
second statement won't even compile. Why? No evaluations are
done at macro compile time; hence the second %LET is ill formed
(no equal sign). Why did it work in open code? There,
evaluation is done in determining what the %LET statement is.
Fortunately the open code language is weak containing only
%GLOBAL, %* (and /**/-comments), %LET, and %PUT statements plus
macro functions and macro invocation. Consequently one can go
for years without finding the need to know the two languages
behave differently. however, when you expect consistency, you
also have to specify consistent with what language.
In short the consistency that you expected would force * to begin
a macro instruction. But the macro language has no *
instruction, so there is no inconsistency. It was your belief,
"When a set of symbols has meaning in two languages that meaning
must be the same in both languages.", that was wrong, i.e.
inconsistent with the facts of the matter.
Should one conclude that it is wrong to write *-comments inside
macros? No. It is nice to be able to generate SAS *-comments
inside macros. It is only wrong to think that they are macro
instruction comments. On the other hand, it is wise to avoid *-
comments inside macros unless you have a real need for them. Why
are they important? They go on the log generated by MPRINT, i.e.
they do what they always do - they make comments about SAS code,
not macro code.
Ian Whitlock
==================
Date: Fri, 8 Jul 2005 12:13:38 -0400
Reply-To: "Buchanan, Gordon" <gordon.buchanan@GMACRFC.COM>
Sender: "SAS(r) Discussion"
From: "Buchanan, Gordon" <gordon.buchanan@GMACRFC.COM>
Subject: Re: Comment in a macro - puzzling
What you all say makes sense. I guess I got confused by the
inconsistancy here because if you do the following outside of a
macro, then you get the shown result. Anyone care to explain
this?
* %let a=45;
%put &a;
WARNING: Apparent symbolic reference A not resolved.
&a
|