Previous Page | Next Page

Macro Language Elements

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.
%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.

Previous Page | Next Page | Top of Page