Introduction to the Macro Facility |
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.
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, while others are valid only in macro definitions. For a complete list of macro statements, see Macro Statements.
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, while the %UPCASE function converts characters to uppercase. A special category of macro functions, the macro quoting functions, mask special characters so 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. For a discussion of the macro quoting functions, see Macro Quoting. For the syntax of calling selected Base SAS functions with %SYSFUNC, see Syntax for Selected Functions Used with the %SYSFUNC Function.
Autocall macros are macros defined by SAS that perform common tasks, such as trimming leading or trailing blanks from a macro variable's value or returning the data type of a value. For a list of autocall macros, see Selected Autocall Macros Provided with SAS Software.
Automatic macro variables are macro variables created by the macro processor. For example, SYSDATE contains the date SAS is invoked. See Macro Language Elements for a list of automatic macro variables.
Interfaces with the macro facility provide a dynamic connection between the macro facility and other parts of SAS, such as the DATA step, SCL code, the SQL procedure, and 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.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.