Date: Wed, 12 May 2004 09:17:55 -0400
Reply-To: Quentin McMullen <quentin_mcmullen@BROWN.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Quentin McMullen <quentin_mcmullen@BROWN.EDU>
Subject: Re: Scope of Macro Variables
On Tue, 11 May 2004 23:45:51 -0400, PCW <walker.627@COMCAST.NET> wrote:
>I want to create a macro variable during a macro execution using call
>symput. Then, I want this macro variable to be available AFTER the macro
>has executed, say for use in a second macro. IS THIS POSSIBLE?
>
>For sake of illustration, here is some code. Suppose that the following
>macro %first is stored in an autocall library (important).
>
>%macro first;
> data temp;
> x=257;
> run;
>
> data _null_;
> set temp;
> call symput('mynumber',x);
> run;
>%mend first;
>
>Now suppose that I call the macro.
>
> %first
>
>Now suppose that I want to see what macro variables are available on the
>macro symbol table.
>
> %put _all_;
>
>I find that the macro variable &mynumber is not available. Even if I add
>the line "%global mynumber;" to the macro definition, &mynumber is still
>not available outside of the macro.
>
>Is there a way to make &mynumber available for later use outside of the %
>first macro???
Hi,
I appreciate your taking the time to post simple example code. But in
this case, I think you may have simplified too much? When I run the code
you submitted, the macro *does* create a global macro variable &mynumber.
This has to do with peculiarities in the way that symput handles issues of
scope (because %first does not have a local symbol table, and symput
cannot create a local symbol table, symput writes to global symbol table).
Of course, as others have written, %global should also work. %gloabal
will NOT work if MYNUMBER is a parameter of %first.
Below is a log of my running your posted coode:
1 %macro first;
2 data temp;
3 x=257;
4 run;
5
6 data _null_;
7 set temp;
8 call symput('mynumber',x);
9 run;
10 %mend first;
11
12 %first
NOTE: The data set WORK.TEMP has 1 observations and 1 variables.
NOTE: DATA statement used:
real time 1.70 seconds
cpu time 0.06 seconds
NOTE: Numeric values have been converted to character values at the places
given by:
(Line):(Column).
1:89
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: DATA statement used:
real time 0.40 seconds
cpu time 0.00 seconds
13 %put _user_;
GLOBAL MYNUMBER 257
Kind Regards,
--Quentin