defined Determine if a macro variable is defined defined

SAS Macro Programs: defined

$Version: 1.0 (17 Feb 2003)
Michael Friendly
York University


The defined macro ( [download] get defined.sas)

Determine if a macro variable is defined

The DEFINED macro returns a value of 0 (false) if the argument is the name of a non-existent macro variable. It returns a 1 if the macro variable exists in the global macro environment.

Method

You can check if a macro variable has been defined by checking the dictionary.macro or sashelp.vmacro view. This version was provided in a sas-l posting by David Ward.

Parameters

MVAR
The name of a macro variable

Example

The DEFINED macro is usually used within other macros, e.g.,

  %global test;
  %let test=3;
%include macros(defined);        *-- or include in an autocall library;
  %macro testit;
  %if %defined(test)
     %then put TEST is defined as &test;
     %else put TEST is undefined;
  %mend;

  %testit;
TEST is defined as 3

See also