Starting 2009, BASAS provides our members with high quality and practical SAS tips. Thanks to Kirk Paul Lafler, a well-known SAS trainer & author, we will publish his SAS tips on a quarterly basis.
Simple and Effective Macro Coding Techniques for SAS® Users
Kirk Paul Lafler, Software Intelligence Corporation
Printer Friendly Version
The SAS® Macro Language is a powerful tool for extending the capabilities of the SAS System. In this SANDS Newsletter issue, I’ve included three macro-related tips that I use frequently in my own code. These techniques illustrate methods associated with processing statements containing macros; replacing text strings with macro variables; troubleshooting and debugging macros; and embedding macro language code into the SAS System to enhance user productivity.
The SAS System offers users a number of useful system options to help debug macro issues and problems. The results associated with using macro options are automatically displayed on the SAS Log. Specific options related to macro debugging appear in alphabetical order in the table below.
|MACRO||Specifies that the macro language SYMGET and SYMPUT functions be available.|
|MEMRPT||Specifies that memory usage statistics be displayed on the SAS Log.|
|MERROR||Presents Warning Messages when there are misspellings or when an undefined macro is called.|
|MLOGIC||Macro execution is traced and displayed on the SAS Log for debugging purposes.|
|MPRINT||SAS statements generated by macro execution are traced on the SAS Log for debugging purposes.|
|SYMBOLGEN||Displays text from expanding macro variables to the SAS Log.|
The macro language is a wonderful tool for streamlining frequently entered SAS Display Manager System (DMS) commands to reduce the number of keystrokes. By embedding a series of DMS commands inside a simple macro, you’ll not only save by not having to enter them over and over again, but you’ll improve your productivity as well. The following macro code illustrates a series of DMS commands being strung together in lieu of entering them individually on a Display Manager command line. The commands display and expand the SAS Log to full size respectively, and then position the cursor at the top of the log. Once the macro is defined, it can be called by entering %POSTSUBMIT on any DMS command line to activate the commands.
To further reduce keystrokes and enhance user productivity even further, a call to a defined macro can be saved to a Function Key. The purpose for doing this would be to allow for one-button operation of any defined macro. To illustrate the process of saving a macro call to a Function Key, the %POSTSUBMIT macro defined in the previous tip is assigned to Function Key F12 in the KEYS window. The partial KEYS window is displayed to illustrate the process.
If you would like more information or have any questions about this tip, please contact Kirk Paul Lafler, Software Intelligence Corporation at KirkLafler@cs.com. Kirk has been working with the SAS System since 1979 and is a SAS Certified Professional®. His company provides custom SAS programming, application design and development, consulting services, and instructor-led and hands-on SAS training to clients and user around the world. Kirk is the author of four books including PROC SQL: Beyond the Basics Using SAS by SAS Institute. He has published more than three hundred peer-reviewed articles and papers, and has been an Invited speaker and instructor at more than three hundred SAS International, regional, local, and special-interest user group conferences and meetings throughout North America.
Kirk Paul Lafler
Software Intelligence Corporation
P.O. Box 1390
Spring Valley, California 91979-1390
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.
Other brand and product names are trademarks of their respective companies.