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 (September 2002, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 16 Sep 2002 12:30:57 -0700
Reply-To:     Roger DeAngelis <xlr82sas@AOL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Roger DeAngelis <xlr82sas@AOL.COM>
Organization: http://groups.google.com/
Subject:      Re: Dynamic macro variables ?
Content-Type: text/plain; charset=ISO-8859-1

Hi Richard,

Not sure this answers your question, but macro variable xx is local to macro x. I wrap the code in utlmain to aviod accidentally creating a global macro variable.

%utlnopts; %macro utlmain;

%put ******************************; %put ******** &sysmacroname **********; %put _local_;

%macro X;

%local statemnt; %PREP (statemnt) run; /* run here not in prep */

%put &statemnt;

&statemnt;

%Y

%put ******* &sysmacroname *********; %put _local_;

%mend;

%macro Y;

%let yy=local to y;

%put &xx from put statement;

%put ******* &sysmacroname *********; %put _local_;

%mend;

%macro PREP(mv);

data _null_;

z='foo'; call symput( 'xx', z);

%put &sysmacroname; %put _local_;

%mend;

%X

%mend utlmain;

%utlmain;

****************************** ******** UTLMAIN ********** PREP PREP MV statemnt ******* Y ********* Y YY local to y ******* X ********* X XX foo X STATEMNT

Here is another method to avoid global macro variables.

* Sysparm Method %macro utlmain;

%sqftvol(30,7,3,Sysparm=Area Volume);

%Let Area=%sysparms(1); %Let Volume=%sysparms(2);

%put area=&area volume=&volume;

%mend utlmain;

Result

area=210 volume=630

%macro sysparms(idx); %scan(&sysparm,&idx); %mend sysparms;

%macro sqftvol(length,width,height,sysparm=);

%let sysparm= %left(%eval(&length * &width )) %left(%eval(&length * &width * &height ));

%mend sqftvol;

WHITLOI1@WESTAT.COM (Ian Whitlock) wrote in message news:<08B08C9FA5EBD311A2CC009027D5BF8102E2B35A@remailnt2-re01.westat.com>... > Richard, > > One solution would be for %PREP(N) to write %LOCAL statements to a file > (work catalog entry type source) and have %X use %INCLUDE. Oops! %LOCAL > command must be compiled so it cannot be hidden in a %INCLUDE file. > > I would write %STORE(DSN=temp, VAL=) to store the information in a SAS data > set and %GET(DATA=temp, N=) to retrieve value and pass to caller. Then %X > could use a loop to define local variables and retrieve them one at a time > from > %GET > > I have suggested enhancing the %LOCAL command to > > %LOCAL <(mac environment)> varname ; > > If implemented any called macro could store information in a higher level > calling macro if one passes the macro name down to the callee. This would > solve your problem, but I wouldn't wait for it to be implemented. > > IanWhitlock@westat.com > -----Original Message----- > From: Richard A. DeVenezia [mailto:radevenz@IX.NETCOM.COM] > Sent: Sunday, September 15, 2002 1:15 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Dynamic macro variables ? > > > I have macros X and Y(arg) > > X invokes Y, Y needs to history of N previous arg. To store the N previous > args in macro variables, I need N macro variables in scope local to X. I > don't want the macro vars to be global. > > What I want to do is have macro PREP(N) that somehow creates the macro vars > arg1-argN in scope local to X; or at least generate the statements and then > let X execute the statements. > > The following does not work, but demonstrates want I want to do: > > %macro X; > %local statemnt; > %PREP (statemnt) > > %put Statements: &statemnt; > &statemnt; > > %Y > %mend; > > %macro Y; > %put &xx; > %mend; > > %macro PREP(mv); > %let &mv = %nrstr(%%local xx;%%let xx=7;); > %mend; > > %X > > > Richard DeVenezia


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