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 (October 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 27 Oct 2004 14:49:25 -0400
Reply-To:     "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject:      Re: Attempt to %GLOBAL a name which exists in a local environment

Huang, Ya wrote: > Hi there, > > Is there anyway I can make a parameter of a macro to be > a global macro var ? > > 1 %macro a(parm=); > 2 %global parm; > 3 %mend; > 4 > 5 %a(parm=HDL); > ERROR: Attempt to %GLOBAL a name (PARM) which exists in a local > environment. > > Basically, I want to use &parm somewhere else, but it won't been > seen unless I make it global macro var. Declare it as a global > doesn't work as shown above. >

You can't promote the scope of a local variable into the callers scope.

You will need to come up with a 'contract' between macro A and the place that wants to use the value passed to A.

The contract in this case is simply agreeing upon a global macro variable name that does not occur in the scope of A (or any other scope wishing to use this value made globally available) and transferring the value into it.

%macro A(parm=); %global g_parm; %* define contract; %let g_parm=&parm; %* transfer; %* use either &parm or &g_parm in A; %mend;

%A(parm=HDL) ... ... title "&g_parm was yada"; %* use contract;

-- Richard A. DeVenezia http://www.devenezia.com/


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