Defining and Calling Macros

Macros are compiled programs that you can call in a submitted SAS program or from a SAS command prompt. Like macro variables, you generally use macros to generate text. However, macros provide additional capabilities:
  • Macros can contain programming statements that enable you to control how and when text is generated.
  • Macros can accept parameters. You can write generic macros that can serve a number of uses.
To compile a macro, you must submit a macro definition. The following is the general form of a macro definition:
%MACRO macro_name;
<macro_text>
%MEND <macro_name>;
macro_name is a unique SAS name that identifies the macro and macro_text is any combination of macro statements, macro calls, text expressions, or constant text.
When you submit a macro definition, the macro processor compiles the definition and produces a member in the session catalog. The member consists of compiled macro program statements and text. The distinction between compiled items and noncompiled (text) items is important for macro execution. Examples of text items include:
  • macro variable references
  • nested macro calls
  • macro functions, except %STR and %NRSTR
  • arithmetic and logical macro expressions
  • text to be written by %PUT statements
  • field definitions in %WINDOW statements
  • model text for SAS statements and SAS windowing environment commands
When you want to call the macro, you use the form
%macro_name.