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 (November 2004, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: cc: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>

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


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