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

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

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