Chapter 11
Writing Efficient and Portable
Macros
Writing Efficient and Portable Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Keeping Efficiency in Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Writing Efficient Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Use Macros Wisely . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Use Name Style Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Avoid Nested Macro Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Assign Function Results to Macro Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Turn Off System Options When Appropriate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Use the Stored Compiled Macro Facility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Centrally Store Autocall Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Other Useful Efficiency Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Storing Only One Copy of a Long Macro Variable Value . . . . . . . . . . . . . . . . . . . 149
Writing Portable Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Using Portable SAS Language Functions with %SYSFUNC . . . . . . . . . . . . . . . . 150
Example Using %SYSFUNC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Using Automatic Variables with Host-Specific Values . . . . . . . . . . . . . . . . . . . . . 151
Example Using SYSPARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
SYSPARM Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
SYSRC Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Macro Language Elements with System Dependencies . . . . . . . . . . . . . . . . . . . . . 154
Host-Specific Macro Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Naming Macros and External Files for Use with the Autocall Facility . . . . . . . . . 156
Writing Efficient and Portable Macros
The macro facility is a powerful tool for making your SAS code development more
efficient. But macros are only as efficient as you make them. There are several
techniques and considerations for writing efficient macros. You can extend the power of
the macro facility by creating macros that can be used on more than one host
environment. In order to do this, there are additional considerations for writing portable
macros.
143

Get SAS 9.4 Macro Language, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.