SYMEXIST Function

Returns an indication of the existence of a macro variable.
Type: DATA step function

Syntax

SYMEXIST (argument)

Required Argument

argument
can be one of the following items:
  • the name of a macro variable within quotation marks but without an ampersand
  • the name of a DATA step character variable, specified with no quotation marks, which contains a macro variable name
  • a character expression that constructs a macro variable name

Details

The SYMEXIST function searches any enclosing local symbol tables and then the global symbol table for the indicated macro variable. The SYMEX/IST function returns one of the following values:
  • 1 if the macro variable is found
  • 0 if the macro variable is not found

Example: Using SYMEXIST Function

The following example of the %TEST macro contains the SYMEXIST function:
%global x;
       %macro test;
       %local y;
       data null;
          if symexist("x") then put "x EXISTS";
                                 else put "x does not EXIST";
          if symexist("y") then put "y EXISTS";
                                 else put "y does not EXIST";
          if symexist("z") then put "z EXISTS";
                                 else put "z does not EXIST";
       run;
       %mend test;
       %test;
In the previous example, executing the %TEST macro, which contains the SYMEXIST function, writes the following output to the SAS log:
x EXISTS
y EXISTS
z does not EXIST