|
Wow,
I was going to get back to this post but seeing that Ian has gobe through and elaborated better than I could I will wait and see if Ben tells us why he wants a macro array.
Great explaination Ian as always.
Toby Dunn
________________________________
From: SAS(r) Discussion on behalf of Ian Whitlock
Sent: Sat 11/27/2004 8:32 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: scope of macro variables
Ben,
Macro variable created in a macro are local to that executing macro unless they exist in some outer environment. Hence the
macro variables V1, V2, ... die with the end of the execution
of X.
Making the variables global makes them visible outside the macro,
but in general leads to poor programming habits. What should you do? That depends on your problem, and so far I only know about
some code. One solution is move the %PUT statement inside the macro.
If you want an array of macro variables perhaps you should use
proc sql noprint;
select name into: v1 - v999999
from o;
quit ;
and skip the macro entirely. On the other hand, the reference
%scan (&vlst , &i)
is no harder than the reference
&&v&i
So why do you want an array?
Ian_Whitlock@comcast.net
==================================
Date: Sat, 27 Nov 2004 07:51:19 -0500
Reply-To: Ben <benpub7@YAHOO.COM>
Sender: "SAS(r) Discussion"
From: Ben <benpub7@YAHOO.COM>
Subject: scope of macro variables
data x;
array a[100] (1 23 45 12 21 .....);
run;
proc contents data=x out=o;
run;
proc sql noprint;
select name into: vlst separated by ' '
from o;
%macro x;
%let i=1;
%do %until(%scan(&vlst,&i,' ')=);
%let v&i=%scan(&vlst,&i, ' ');
%let i=%eval(&i+1);
%end;
%mend x;
%x;
%put _user_;
why didn't I see macro varibales v1 v2 v3 v4......;
if I define them all global variables, I wonder if it has some side effects,
any opionion?
Thanks
|