%SYMEXIST Function
Returns an indication of the existence of a macro
variable.
Syntax
%SYMEXIST(macro-variable-name)
Required Argument
- macro-variable-name
-
is the name of a macro
variable or a text expression that yields the name of a macro variable.
Details
The %SYMEXIST function
searches any enclosing local symbol tables and then the global symbol
table for the indicated macro variable and returns one of the following
values:
-
1
if the macro variable is found
-
0
if the macro variable is not found
Example: Using %SYMEXIST Macro Function
The following example
uses the %IF %THEN %ELSE macro statement to change the value of
1
and
0
to
TRUE
and
FALSE
respectively:
%global x;
%macro test;
%local y;
%if %symexist(x) %then %put %nrstr(%symexist(x)) = TRUE;
%else %put %nrstr(%symexist(x)) = FALSE;
%if %symexist(y) %then %put %nrstr(%symexist(y)) = TRUE;
%else %put %nrstr(%symexist(y)) = FALSE;
%if %symexist(z) %then %put %nrstr(%symexist(z)) = TRUE;
%else %put %nrstr(%symexist(z)) = FALSE;
%mend test;
%test;
In the previous example,
executing the %TEST macro writes the following output to the SAS log:
%symexist(x) = TRUE
%symexist(y) = TRUE
%symexist(z) = FALSE