Macro Statements

Using Macro Statements

A macro language statement instructs the macro processor to perform an operation. It consists of a string of keywords, SAS names, and special characters and operators, and it ends in a semicolon. Some macro language statements are used only in macro definitions, but you can use others anywhere in a SAS session or job, either inside or outside macro definitions (referred to as open code). The following table lists macro language statements that you can use in both macro definitions and open code.
Macro Language Statements Used in Macro Definitions and Open Code
Statement
Description
%* comment
Designates comment text.
%COPY
Copies specified items from a SAS library.
%DISPLAY
Displays a macro window.
%GLOBAL
Creates macro variables that are available during the execution of an entire SAS session.
%INPUT
Supplies values to macro variables during macro execution.
%LET
Creates a macro variable and assigns it a value.
%MACRO
Begins a macro definition.
%PUT
Writes text or the values of macro variables to the SAS log.
%SYMDEL
Deletes the indicated macro variable named in the argument.
%SYSCALL
Invokes a SAS call routine.
%SYSEXEC
Issues operating system commands.
%SYSLPUT
Defines a new macro variable or modifies the value of an existing macro variable on a remote host or server.
%SYSMACDELETE
Deletes a macro definition from the WORK.SASMACR catalog.
%SYSMSTORECLEAR
Closes stored compiled macros and clears the SASMSTORE= library.
%SYSRPUT
Assigns the value of a macro variable on a remote host to a macro variable on the local host.
%WINDOW
Defines customized windows.
The following table lists macro language statements that you can use only in macro definitions.
Macro Language Statements Used in Macro Definitions Only
Statement
Description
%ABORT
Stops the macro that is executing along with the current DATA step, SAS job, or SAS session.
%DO
Begins a %DO group.
%DO, Iterative
Executes statements repetitively, based on the value of an index variable.
%DO %UNTIL
Executes statements repetitively until a condition is true.
%DO %WHILE
Executes statements repetitively while a condition is true.
%END
Ends a %DO group.
%GOTO
Branches macro processing to the specified label.
%IF-%THEN/%ELSE
Conditionally processes a portion of a macro.
%label:
Identifies the destination of a %GOTO statement.
%LOCAL
Creates macro variables that are available only during the execution of the macro where they are defined.
%MEND
Ends a macro definition.
%RETURN
Causes normal termination of the currently executing macro.

Macro Statements That Perform Automatic Evaluation

Some macro statements perform an operation based on an evaluation of an arithmetic or logical expression. They perform the evaluation by automatically calling the %EVAL function. If you get an error message about a problem with %EVAL when a macro does not use %EVAL only, check for one of these statements. The following macro statements perform automatic evaluation:
  • %DO macro-variable=expression %TO expression <%BY expression>;
  • %DO %UNTIL(expression);
  • %DO %WHILE(expression);
  • %IF expression %THEN action;
For details about operands and operators in expressions, see Macro Expressions.