Date: Tue, 30 Nov 2004 01:24:29 +0000
Reply-To: iw1junk@COMCAST.NET
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <iw1junk@COMCAST.NET>
Subject: Re: Use a do loop to process a dataset for as many times as there
are parameters
Toby,
Your rule for local is dangerously ambiguous.
A macro variable's scope depends on the environment in which this macro executes. When a macro variable's scope must be determined, it is in the nearest outer environment already containing a variable of that name, unless it does not exist in any outer environment, in which case it is local.
This means that no macro can guarantee the integrity of its macro variables when it calls another macro. It is the job of the called macro to preserve this integrity by declaring its own variables local. Hence it is most important to declare variables local whenever that is possible. It is even more important (sort of like a more perfect union) to declare commonly named looping indices local.
Ian_Whitlock@comcast.net
=================================
Date: Mon, 29 Nov 2004 14:28:42 -0600
Reply-To: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Sender: "SAS(r) Discussion"
From: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Subject: Re: Use a do loop to process a dataset for as many times as there
are parameters
Comments: To: "Case,Todd" <Todd.Case@FRX.COM>
Content-Type: text/plain; charset="iso-8859-1"
Todd,
When using open sas code do loops the index becomes a variable in the data set. When using macro do loops the index becomes a macro variable that is local (unless specified otherwise) to that macro.
%MACRO PARM(nparm=);
%do i=1 %to &nparm;
proc sort data=eff(where=(param=&I))
out=d&i;
by &idvars;
run;
%end;
%MEND PARM;
%PARM(nparm=2)
HTH
Toby Dunn
|