How to Develop User Friendly Macros

SAS® macros help automate tasks that are done repeatedly. However, if they are not easy to use or debug, they may never be used. This paper will describe approaches to developing and maintaining SAS macros that are easy to use. Some of the topics covered include:
  • effective documentation of macro header
  • portable code for use with different OS
  • error and warning message handling
  • paper and online documentation
  • use of nested macros and nested macro variables
  • keeping macros simple for debugging

A little effort can go a long way towards creating a successful SAS macro. This paper will present tips and techniques that are not always obvious. Besides getting the resulting numbers to the user, a user friendly macro can enhance the entire experience.

Macros Overview
SAS macros are great at automating repetitive tasks as a code generator. However, there are some features of macros that make them difficult to understand and debug. The syntax of SAS macros is similar to that of traditional SAS data step but there is a level of abstraction. To accomplish its code generating function, SAS macros add percent signs (%) and ampersand (&) in front of specified commands and variables. This layer can be confusing since it requires you to resolve the macro before understanding what is being processed. This confusion is compounded when things are nested. Macro variables can be nested by resolving into other macro variables. Macros themselves can call other macros which creates a nested looping structure. Macro code can sometimes be spaghetti code. It is therefore helpful for the user and the person maintaining the macro to make the macros user friendly.

One of the most straightforward ways to make SAS macros user friendly is to enhance the documentation that accompanies the macro. This is an essential part of software that some programmers overlook when delivering macros to users. There are many different forms of documentation and the more that is available, the greater the chance of connecting with the user. This paper will summarize eleven different types of documentation. The content can overlap among the different types but each method has its own strengths.

HTML – Documentation can be delivered as HTML pages within an intranet or Internet. This is readily available to all users. The website has the following advantages:

  1. Accessibility from any computer connected to the network.
  2. Hyperlinks to quickly navigate to specified content.
  3. Search engine to find specific content.
  4. Graphics for capturing screen shots and other diagrams for more effective communication.

PDF - Similar to HTML, a PDF file can be delivered within an intranet or Internet. Its strengths are similar to HTML with some distinguishing features:

  1. Can be delivered as one file, as in an email as an attachment, in case the user does not have network access.
  2. PDF format is more consistent for printing on physical paper.The content is locked from changes.

Complete paper found at "How to Develop User Friendly Macros ", related SAS Programming and sample SAS Macros...

Bookmark and Share


  1. Interesting post for SAS Macros. Bt Troung, I have a simple query related to
    1)Conditional processing
    Ÿ2)Parameter validation,
    Can you provide me a simple overview??

  2. Thanks for sharing the valuable information,This is useful information for online learners


  3. Thank you so much for sharing this wonderful information. I find this very useful and informative. keep up this good work.

    SAS training institutes in Chennai

  4. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    sas training institute in Chennai


Post a Comment

Popular posts from this blog

Clinical Trials Terminology for SAS Programmers

Remembering Dad