Date: Tue, 28 Dec 1999 17:17:33 +0100
Reply-To: Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Subject: Re: sas macros - beginners question
Content-Type: text/plain; charset="iso-8859-1"
Richard / Raymond,
That is very tricky and can not be done like that. Macros are run before
data steps, not within, only after a RUN; Thus a macro choice can not be
dependent on the contents of (the names in) a dataset. Furthermore take care
to use the reserved word MACRO (without the percent) as a variable name or
whatever; it is an old style command, still functional.
There are solutions to such a problem. One possibility would be something
like:
DATA new;
SET old; * (with a.o. variable MacroVar);
IF UPCASE(MacroVar)="ANYVALUE" THEN
DO;
%ANYVALUE(); Unconditional contents resolving to data step code already
generated before data step run by macro;
END;
ELSE IF UPCASE(MacroVar)="OTHERVAL" THEN
DO;
%OTHERVAL(); Unconditional contents resolving to data step code already
generated before data step run by macro;
END;
ELSE.............;
RUN;
Furthermore I think your macro RunMacro should look something like
(untested):
%macro runmacro (macname);
%STR(%%)%STR(&macname);
%mend;
and called as %RunMacro(MyMacro);
Manipulation of &'s and %'s is very tricky and should be applied with care,
using quoting functions. Could you use SYMPUT to obtain a single value from
within a data step outside it (after RUN;) as a macro variable?
Why would you run macro's based on the macro name within a dataset? Can't
you do with one macro only, which you feed the contents of some (character)
variable from a dataset to act upon accordingly? The macro at the moment of
data step run already has resolved and the resulting code will handle the
parameter contents as desired.
Regards - Jim.
--
Y. Groeneveld, MSc IMRO TRAMARKO tel. +31 412 407 070
senior statistician, P.O. Box 1 fax. +31 412 407 080
head IT department 5350 AA BERGHEM IMRO TRAMARKO: a CRO
J.Groeneveld@ITGroups.com the Netherlands in clinical research
I wish you a merry Christmas and a happy, compatible y²°°°
"My job is to keep my computer working." - Jim Groeneveld
> -----Original Message-----
> From: Richard Paterson [SMTP:RichardP@OCS-CONSULTING.COM]
> Sent: Tuesday, December 28, 1999 3:46 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: FW: sas macros - beginners question
>
> > Dear list,
> >
> > I have many macros I would like to run sequentially. They are stored in
> a
> > dataset.
> >
> >
> > data macros;
> > input repnum macnum macro $;
> > cards;
> > 1 1 macro1
> > 1 2 macro2
> > ;
> > run;
> >
> >
> > I would like to run them sequentially, so I tried
> >
> >
> > %macro runmacro(macro);
> > ¯o;
> > %mend;
> >
> >
> >
> > data test;
> > set macros;
> > %%runmacro(macro); ------- here I hoped the runmacro(macro) would
> > resolve to the macro name.
> > run;
> >
> >
> >
> >
> > Can someone show me where I am going wrong please ?
> >
> > Dank je
> >
> > can you CC me in the reply as I can't read the list yet.
> >
> >
> > Raymond Ebben
> > Trainee SAS Programmer
> >
> >
> >
> >
> >