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 (July 2001, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 2 Jul 2001 15:22:49 -0400
Reply-To:     "Fehd, Ronald J." <rjf2@CDC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Fehd, Ronald J." <rjf2@CDC.GOV>
Subject:      Re: macro help: reference %global macro vars
Comments: To: Ian Whitlock <WHITLOI1@WESTAT.com>
Content-Type: text/plain; charset="iso-8859-1"

> From: Ian Whitlock [mailto:WHITLOI1@WESTAT.com] > This is a nasty version 8 bug. > You cannot global a local variable.

I agree. However, you can 'copy' a local mac-var value to a global mac-var.

> In version 6 an error was reported in any attempt to do so.

yes, my memory of error messages supports that.

> In running your > code under version 8 there are no error messages! Line 82, > "%global X;", is > simply ignored. I would very much prefer to leave it as an > error since it > is an error and the programmer should be made aware of his mistake.

I was chagrined to _not_ see any error message on this %global X; statement. The %put supported my assumption -- listing the %local value of X -- that once mac-var X had been added to the %local symbol table there would be no way to access the %global variable. except, perhaps, thru work-arounds, as provided by other posters accessing the system tables.

> Who asked for this behavior. Is it a mistake by accident or design?

ill-informed bxor undereducated, I'm sure.

Little birdies will have to rescue themselves from this one.

Ron Fehd the macro maven CDC Atlanta GA USA RJF2@cdc.gov

> -----Original Message----- > From: Fehd, Ronald J. [mailto:rjf2@CDC.GOV] > Sent: Monday, July 02, 2001 10:12 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: macro help: reference %global macro vars > > > > From: ZPAN [mailto:zpan@AOL.COM] > > How can I reference GLOBAL macro x within macro NEW? > > > %global x; %*this is unnecessary in open code; > > 74 %macro newY(Y=); > 75 %PUT LOCAL: ; > 76 %PUT _local_; > 77 %put GLOBAL X: &x;/* THIS IS TO REFERENCE LOCAL MACRO > VARIABLE X*/ > 78 %LOCAL X; > 79 %LET X = &Y.; > 80 %PUT _local_; > 81 > 82 %global X; > 83 %put global or local x: &X.; > 84 %PUT _local_; > 85 %mend; > 86 > 87 %newy(Y=2); > LOCAL: > NEWY Y 2 > GLOBAL X: 1 > NEWY X 2 > NEWY Y 2 > global or local x: 2 > NEWY X 2 > NEWY Y 2 > 88 %put global: &x;/* THIS IS TO REFERENCE LOCAL MACRO VARIABLE X*/ > global: 1 > > You are not going to be able to declare X in a %local symbol table > -- by having it in the parameter list -- > before you try to access %global X. > > This concept is known as masking: > You can access %global X until you mask it with a %local declaration. > Your declaration was in the parameter list of macro NEW. > My example %put the %global X, then declared X %local and > %put the local > value. You will not be able to switch back to accessing the %global X. > > As always the important question is: Why do you want to do this? > > This is major pain in the program for new macro users: > keeping track of which macro var they are using. > > It often shows up as a major Can't-figure-this-out > when using the same loop index -- I -- in a calling and a > called macro. > > 14 %macro CALLING(A); > 15 %DO I = 1 %TO 3;%PUT CALLING MSG: &I.;%CALLED(&I);%END; > 16 %PUT _LOCAL_;%MEND; > 17 %macro CALLED(B); > 18 %DO I = 1 %TO 3;%PUT CALLED MSG: &I.;%END;%MEND; > 19 %CALLING(1); > CALLING MSG: 1 > CALLED MSG: 1 > CALLED MSG: 2 > CALLED MSG: 3 > CALLING I 5 > CALLING A 1 > > mac-var I is %local to CALLING > macro CALLED resets it and increments it thru its loop, > and on exit, back to CALLING I fails the CALLING loop value and exits. > To fix this, add a > %local I; > to macro CALLED. > > Ron Fehd the macro maven CDC Atlanta GA USA RJF2@cdc.gov > OpSys: WinNT Ver: 8.1 > ---> cheerful provider of TESTED SAS code!*! <--- > By using your intelligence you can sometimes make your > problems twice as > complicated. > -- Ashleigh Brilliant >


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