Date: Sat, 31 Mar 2007 18:14:55 -0500
Reply-To: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Subject: Re: code challenge: subroutine checks that caller has %local
mvars to
Martin Gregory wrote:
> It looks like sashelp.vmacro is treated like a stack: if you could
> rely on that, then you'd know what the calling macro is.
Thediscovery process that supplies the DICTIONARY.MACRO view certainly does
appear to deliver information in a stack. But there is no indication of the
call stack, which obviously must be known to the macro supervisor. See
option MPRINTNEST.
Without documentation stating the view is a stack, I would argue against
building a macro library on the potential sandpit it will not be in the
future.
Sample of a recursive macro:
--------------------------------------------
%macro recurse (n=1);
%if &n > 10 %then %return;
%local MyMacroVar ;
%let MyMacroVar = %sysevalf(&n**2);
title "recurse called with n=&n";
proc print data=sashelp.vmacro;
where name like 'MY%';
run;
%recurse (n=%eval(&n+1))
%mend;
options ;
%put %sysfunc(pathname(work));
ods listing close;
ods html file="%sysfunc(pathname(work))\recurse-report.html" style=meadow;
%let myMacroVar = CornerStone;
%recurse;
%symdel myMacroVar;
ods html close;
--------------------------------------------
--
Richard A. DeVenezia
http://www.devenezia.com/