Keeping Efficiency in Perspective
Efficiency is an elusive thing, hard to quantify and harder still to define. What works
with one application might not work with another, and what is efficient on one host
environment might be inefficient on a different system. However, there are some
generalities that you should keep in mind.
Usually, efficiency issues are discussed in terms of CPU cycles, elapsed time, I/O hits,
memory usage, disk storage, and so on. This section does not give benchmarks in these
terms because of all the variables involved. A program that runs only once needs
different tuning than a program that runs hundreds of times. An application running on a
mainframe has different hardware parameters than an application developed on a
desktop PC. You must keep efficiency in perspective with your environment.
There are different approaches to efficiency, depending on what resources you want to
conserve. Are CPU cycles more critical than I/O hits? Do you have lots of memory but
no disk space? Taking stock of your situation before deciding how to tune your programs
is a good idea.
The area of efficiency most affected by the SAS macro facility is human efficiency —
how much time is required to both develop and maintain a program. Autocall macros are
particularly important in this area because the autocall facility provides code reusability.
Once you develop a macro that performs a task, you can save it and use it for the
• in the application that you developed it for
• in future applications without any further work
A library of reusable, immediately callable macros is a boon to any application
The stored compiled macro facility (described in Chapter 9, “Storing and Reusing
Macros,” on page 115) might reduce execution time by enabling previously compiled
macros to be accessed during different SAS jobs and sessions. But it is a tool that is
efficient only for production applications, not during application development. So the
efficiency techniques that you choose depend not only on your hardware and personnel
situation, but also on the stage that you have reached in your application development
Also, remember that incorporating macro code into a SAS application does not
automatically make the application more efficient. When designing a SAS application,
concentrate on making the basic SAS code that macros generate more efficient. There
are many sources for information about efficient SAS code, including SAS Programming
Tips: A Guide to Efficient SAS Processing.
Writing Efficient Macros
Use Macros Wisely
An application that uses a macro to generate only constant text can be inefficient. In
general, for these situations consider using a %INCLUDE statement. The %INCLUDE
statement does not have to compile the code first (it is executed immediately). Therefore,
144 Chapter 11 • Writing Efficient and Portable Macros