Date: Tue, 22 Oct 2002 11:40:17 -0400
Reply-To: Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject: Re: Macro variable in Macro Name
Content-Type: text/plain; charset="iso-8859-1"
No macro references are resolved between %MACRO and %MEND. Hence you cannot
have a variable named macro.
On the other hand there is no need have a variable name for one macro. At
least, I cannot conceive of one. You probably want several macros (all with
fixed names) and to be able to use a variable to specify which of the macros
you want to execute. This can be quite useful.
Here is code to illustrate, that works fine in version 8.2 and 6.12.
%let suffix = ABC;
%put THATABC executing ;
Somewhere between version 6.06 and 8.2, the resolution of the variable in
the macro name was considered a bug, since it didn't do that in version 5.
If you are operating with a system from this period, then you can use
%let mac = that&suffix ;
Both work by forcing the resolution of &SUFFIX before calling the macro.
The second works because the bug was only partially fixed during period
where it was "fixed". Their advantage in 8.2 is that they are version
independent. Due to screaming the bug was revived, but I am not sure in
From: Bill Anderson [mailto:wnilesanderson@COX.NET]
Sent: Tuesday, October 22, 2002 11:12 AM
Subject: Macro variable in Macro Name
I would like to be able to name a macro, according to the value of a macro
variable that is defined before the macro code. Here is a very abbreviated
version of the code I tried.
%let suffix = ABC;
/* SAS code; */
The intention is the the compiled macro would have the name thatABC, and
then the statement %thatABC would invoke the macro. But the SAS macro
compiler balks, and the log contains the messages:
ERROR: Expected semicolon not found. The macro will not be compiled.
ERROR: A dummy macro will be compiled.
According to the SAS MACRO manual (version 8, page 23), "You can use these
[macro variable] references anywhere in a SAS program". I have learned to
take this statement with a grain of salt, and the above situation seems to
be another example. Any suggestions would be appreciated.
One might wonder why I would want to do such a thing. The reason is that I
have a bunch of files which perform the same logical operation, although
the specific macro code is quite different from file to file. (Actually
about 10 different algorithms for data imputation, and I want details of the
specific algorithm to remain hidden in the individual files.) I want to
preserve as much parallelism as possible, and I successfully use the suffix
in titles, variable labels, SAS data set names, and external file names. I
would like to to be able to do the same thing with the macro names, but have
come to the above described sticky point.