%do n=1 %to &number;
&name&n
%end;
%mend names;
The macro NAMES creates a series of names by concatenating the value of the
parameter NAME and the value of the macro variable N. You supply the stopping value
for N as the value of the parameter NUMBER, as in the following DATA statement:
data %names(name=dsn,number=5);
Submitting this statement produces the following complete DATA statement:
data dsn1 dsn2 dsn3 dsn4 dsn5;
Note: You can also execute a %DO loop conditionally with %DO %WHILE and %DO
%UNTIL statements. For more information, see “%DO %WHILE Statement” on
page 312 and “%DO %UNTIL Statement” on page 311.
Generating a Suffix for a Macro Variable Reference
Suppose that, when you generate a numbered series of names, you always want to put
the letter X between the prefix and the number. The macro NAMESX inserts an X after
the prefix you supply:
%macro namesx(name=,number=);
%do n=1 %to &number;
&name.x&n
%end;
%mend namesx;
The period is a delimiter at the end of the reference &NAME. The macro processor uses
the delimiter to distinguish the reference &NAME followed by the letter X from the
reference &NAMEX. Here is an example of calling the macro NAMESX in a DATA
statement:
data %namesx(name=dsn,number=3);
Submitting this statement produces the following statement:
data dsnx1 dsnx2 dsnx3;
For more information about using a period as a delimiter in a macro variable reference,
see Macro Variables on page 23.
Other Features of the Macro Language
Although subsequent sections go into far more detail on the various elements of the
macro language, this section highlights some of the possibilities, with pointers to more
information.
macro statements
This section has illustrated only a few of the macro statements, such as %MACRO
and %IF-%THEN. Many other macro statements exist, some of which are valid in
open code, and others are valid only in macro definitions. For a complete list of
macro statements, see “Macro Statements” on page 158.
Other Features of the Macro Language 13
macro functions
Macro functions are functions defined by the macro facility. They process one or
more arguments and produce a result. For example, the %SUBSTR function creates a
substring of another string, when the %UPCASE function converts characters to
uppercase. A special category of macro functions, the macro quoting functions, mask
special characters so that they are not misinterpreted by the macro processor.
There are two special macro functions, %SYSFUNC and %QSYSFUNC, that
provide access to SAS language functions or user-written functions generated with
SAS/TOOLKIT. You can use %SYSFUNC and %QSYSFUNC with new functions
in Base SAS software to obtain the values of SAS host, base, or graphics options.
These functions also enable you to open and close SAS data sets, test data set
attributes, or read and write to external files. Another special function is
%SYSEVALF, which enables your macros to perform floating-point arithmetic.
For a list of macro functions, see “Macro Functions” on page 160. For a discussion
of the macro quoting functions, see Macro Quoting on page 82. For the syntax of
calling selected Base SAS functions with %SYSFUNC, see Syntax for Selected
Functions with the %SYSFUNC Function on page 439.
autocall macros
Autocall macros are macros defined by SAS that perform common tasks such as the
following:
trimming leading
trailing blanks from a macro variable's value
returning the data type of a value
For a list of autocall macros, see “Selected Autocall Macros Provided with SAS
Software” on page 171.
automatic macro variables
Automatic macro variables are macro variables created by the macro processor. For
example, SYSDATE contains the date SAS is invoked. See Chapter 12, “Macro
Language Elements,” on page 157 for a list of automatic macro variables.
macro facility interfaces
Interfaces with the macro facility provide a dynamic connection between the macro
facility and other parts of SAS, such as the following:
DATA step
SCL code
SQL procedure
SAS/CONNECT software
For example, you can create macro variables based on values within the DATA step
using CALL SYMPUT and retrieve the value of a macro variable stored on a remote
host using the %SYSRPUT macro statement. For more information about these
interfaces, see Interfaces with the Macro Facility on page 103.
14 Chapter 1 Introduction to the Macro Facility
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset