|
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
>
|