You can learn more about Michele and read a free chapter from each of her books here. And if you like this week's tip, take a look at these previously featured excerpts from Michele's work: Selecting variables to include in output and Using %NRSTR to mask macro triggers.
The following excerpt is from SAS author Michele Burlew and her book "SAS Macro Programming Made Easy, Second Edition" Copyright © 2006, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. (please note that results may vary depending on your version of SAS software)
Building a Macro Program in Four Steps
The four basic steps in building a macro program are
- Write, test, and debug the SAS program(s) that you want the macro program to build. Do not use any macro variables or macro language statements in this step.
- Remove hard-coded programming constants from the program(s) in Step 1 and replace these constants with macro variables. Hard-coded programming constants are items like the values on a WHERE statement. Use %LET statements in open code to define the macro variables. Test and debug the program(s). Use the SYMBOLGEN option to verify the results of using the macro variables.
- Create macro program(s) from the program(s) in Step 2. Add parameters to the macro program(s) if appropriate. Most likely, it would be appropriate to make the macro variables that you define in Step 2 parameters to the macro program(s) that you write in this step. Use SAS options MPRINT and SYMBOLGEN to review the results of processing this macro program.
- Refine and generalize the macro program(s) in Step 3 by adding macro language statements like %IF-%THEN and %DO groups. After several macro programs are tested in Step 3, write programming statements to combine the macro programs into one macro program. Test the macro programming logic. Use the SAS options MPRINT, SYMBOLGEN, and MLOGIC to verify that your macro program works correctly.