O'Reilly logo

SAS 9.4 Macro Language, 5th Edition by

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

%DO macro-variable=expression %TO expression <%BY expression>;
%DO %UNTIL(expression);
%DO %WHILE(expression);
%IF expression %THEN action;
For more information about operands and operators in expressions, see Chapter 6,
“Macro Expressions,” on page 73.
Macro Functions
Using Macro Functions
A macro language function processes one or more arguments and produces a result. You
can use all macro functions in both macro definitions and open code. Macro functions
include character functions, evaluation functions, and quoting functions. The macro
language functions are listed in the following table.
Table 12.3 Macro Functions
Function Description
%BQUOTE,
%NRBQUOTE
Mask special characters and mnemonic operators in a resolved
value at macro execution.
%EVAL Evaluates arithmetic and logical expressions using integer
arithmetic.
%INDEX Returns the position of the first character of a string.
%LENGTH Returns the length of a string.
%QUOTE, %NRQUOTE Mask special characters and mnemonic operators in a resolved
value at macro execution. Unmatched quotation marks (“ ”) and
parentheses ( () ) must be marked with a preceding %.
%SCAN, %QSCAN Search for a word specified by its number. %QSCAN masks
special characters and mnemonic operators in its result.
%STR, %NRSTR Mask special characters and mnemonic operators in constant text
at macro compilation. Unmatched quotation marks (“ ”) and
parentheses ( () ) must be marked with a preceding %.
%SUBSTR, %QSUBSTR Produce a substring of a character string. %QSUBSTR masks
special characters and mnemonic operators in its result.
160 Chapter 12 Macro Language Elements
Function Description
%SUPERQ Masks all special characters and mnemonic operators at macro
execution but prevents resolution of the value.
%SYMEXIST Returns an indication as to whether the named macro variable
exists.
%SYMGLOBL Returns an indication as to whether the named macro variable is
global in scope.
%SYMLOCAL Returns an indication as to whether the named macro variable is
local in scope.
%SYSEVALF Evaluates arithmetic and logical expressions using floating-point
arithmetic.
%SYSFUNC,
%QSYSFUNC
Execute SAS functions or user-written functions. %QSYSFUNC
masks special characters and mnemonic operators in its result.
%SYSGET Returns the value of a specified host environment variable.
%SYSMACEXEC Indicates whether a macro is currently executing.
%SYSMACEXIST Indicates whether there is a macro definition in the
Work.SASMacr catalog.
%SYSMEXECDEPTH Returns the depth of nesting from the point of call.
%SYSMEXECNAME Returns the name of the macro executing at a nesting level.
%SYSPROD Reports whether a SAS software product is licensed at the site.
%UNQUOTE Unmasks all special characters and mnemonic operators for a
value.
%UPCASE, %QUPCASE Convert characters to uppercase. %QUPCASE masks special
characters and mnemonic operators in its result.
Macro Character Functions
Character functions change character strings or provide information about them. The
following table lists the macro character functions.
Table 12.4 Macro Character Functions
Function Description
%INDEX Returns the position of the first character of a string.
%LENGTH Returns the length of a string.
Macro Functions 161

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required