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 (April 1999, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 29 Apr 1999 12:48:22 -0400
Reply-To:   "Ward, David" <dward@INNOVEX-DAS.COM>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   "Ward, David" <dward@INNOVEX-DAS.COM>
Subject:   Re: Macro for testing for existence of a macro variable
Content-Type:   text/plain

Gerald and SAS-L'ers: Try this macro: It returns the scope of a macro variable given the variable name. This is particularly handy inside of nested macros when you want to discover which macro a particular variable is operating inside of. Submit "%put %mvexist(sysdate);" to see how it works.

%macro mvexist (_var); /** OPEN THE VMACRO VIEW WHICH CONTAINS INFO ABOUT MACOR VARS **/ %let dsid=%sysfunc(open(sashelp.vmacro (where=(name="%upcase(&_var)")))); /** FETCH A RECORD INTO THE PDV IF IT EXISTS **/ %let rc=%sysfunc(fetch(&dsid)); /** RETURN VARNUM 1, THE SCOPE **/ %sysfunc(getvarc(&dsid,1)) /** CLOSE THE VIEW **/ %let rc=%sysfunc(close(&dsid)); %mend;

- David Ward

> Gerald Leahy wrote: > > > > Does anyone know of a way to determine whether a macro variable has been > > defined without producing a warning? I've tried using proc sql to > > access dictionary.macros, only to find out the macro needs to be called > > from within a datastep. Macro quoting is not a strong suit, so reading > > about quoting functions has been a little fustrating. I suspect the > > answer lies in %SUPERQ. > > > > Can anybody give me a few lines for checking existence and then > > performing some actions based on the test. > > > > Thanks in advance! > > > > Sample: > > ___________________________________________________________________ > > > > %MACRO VAREXIST(VAR); > > %IF &var is a macro variable %THEN %DO; > > . > > . > > statements; > > . > > . > > %END; > > %ELSE %DO; > > . > > . > > statements; > > . > > . > > %END; > > %MEND VAREXIST; > > > > ___________________________________________________________________ > > > > Gerald Leahy > > leahyg@pprd.abbott.com > > Abbott Laboratories > > D436 AP9A-2 > > (847) 937-2066 >


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