Building efficient multiple purpose SAS macros

Recently, I designed a reporting SAS macro with the requirements that it is efficient and of course has all the other capabilities that the users desired. But what is an efficient SAS macro?

What is efficient?

Does it mean that it is short in code? That it is short in run-time or that it has a lot of functionalities in it? When you have an overall look on the process that you want to cover you also need to consider the creation and maintenance time of macros and the total number of macro’s that is needed for the complete process. A lot of small macros might take more time to create and to maintain than 1 big macro. But that will also depend on the content of each macro. Maintaining a big macro that is very diverse can take more time and effort than maintaining a number of small macros.

How many macros?

So at the design stage of each set of macro’s a number of considerations are important. First of all, the desired end products must be kept in mind at all times. Based on that, look at the level of overlap between the different outputs that are desired. If the overlap is large, say more than 70%, then creating 1 multi-purpose macro might be more efficient than creating a macro for every single variation of the output as it probably will mean that the functionality for creating the different outputs can be shared. When the overlap is smaller, but there are some shared functionalities, then creating a set of separately designed reusable sub-macros is more beneficial to prevent re-programming and make it easier to maintain the set.

Building blocks

The design of a multi-purpose SAS macro is more difficult than simple macros in ensuring that the set-up and functionalities are clear, that nothing is overlooked and that it will be easy to maintain afterwards. My advice is to divide the macro in different building blocks according to these functionalities. For example, the calculations and statistics can be separated from the actual reporting. The different logical building blocks are preferably created as different submacros. This has another efficiency gain as each block can be handled by a different programmer who is an expert in the specific part.

The creative process

A good macro design will improve the efficiency around building the macro and maintaining the macro. Designing the macro will take some time, but you will gain a lot by limiting the amount of re-work and necessary changes afterwards. Designing is a really creative process in which you will have to think of all possible input and output requirements, checks and functionalities. It requires a lot of imagination, re-thinking, content knowledge and focus.

The functional specifications

But only thinking is not enough. It will have to be written down in clear functional specifications based on the user requirements. When writing those and re-reading, often the architect and key users will come up with additional questions and limitations that need to be addressed as well. Doing that before the actual programming phase will also speed up this process and limit the re-work and changes afterwards.

So going back to the original question: What is an efficient SAS macro? That will be a macro which is

  • not too diverse,
  • will combine functionalities if there is a lot of overlap,
  • consists of different building blocks separating functional steps in the process,
  • is designed according to well written functional specifications and
  • will share functionalities with other macros by separately designed sub-macros.

 Please feel free to add or share your own ideas around this subject.

Berber Snoeijer, ClinLine

I you like support on the design of your own SAS macro’s you can contact us via See also our website

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.