Keys to good macro design

This post was kindly contributed by Key Happenings at support.sas.com - go there to comment and to read the full post.

On the final day of SESUG 2010, I only had time to attend one presentation. I chose Frank DiIorio’s %whatChanged: A Tool for the Well-Behaved Macro for two reasons: 1.) Papers about macros are big hits with SAS Tech Report readers and 2.) DiIorio is a longtime SAS user with nearly three decades of SAS experience. The combo was a win-win.

DiIorio opened his presentation by saying that macros can be a force for good or for chaos. “If you turn your programs over to someone who is undisciplined, chaos can emerge from poorly constructed macros,” he said.

His alternative was to provide a macro that will allow programmers to see the effects of their macros. He also gave some best practices for good macro design. DiIorio created %whatChanged because clients and users want your macros to do what YOU say they will do. They shouldn’t be saddled with unintentional macros, data sets or tables. With his macro, you can view a snap shot of your data before and after running your macro. I couldn’t put everything DiIorio said into a small blog post, so I captured his list of good macro design best practices.

Keys to Good Macro Design

  1. Know when a macro is and is not necessary.
  2. Use keyword parameters and values consistently.
  3. Use consistent program structure.
  4. Know when to redesign. (If you have the luxury of time.)
  5. Communicate with the user and with other programs.
  6. Control macro variable scope.
  7. Implement diagnostic and debugging code.
  8. Use built-in macro tools.
  9. Clearly document the macro.
  10. Produce only what was promised!

SESUG 2010 was a great success and planning is well underway for SESUG 2011. Chairs for SESUG 2011 are Marje Fecht and Barbara Okerson. Subscribe to the SESUG mailing list and follow Stephanie Thompson (@SRT_SESUG) on Twitter to stay up-to-date on 2011 registration and presentaton information.

This post was kindly contributed by Key Happenings at support.sas.com - go there to comment and to read the full post.