SAS author's tip: Building a macro program in 4 steps

0

This week's SAS tip comes from Michele Burlew and her book SAS Macro Programming Made Easy, Second Edition. Michele is the accomplished author of  7 SAS Press books and a much-respected SAS expert.

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
Share

About Author

Shelly Goodin

Social Media Specialist, SAS Publications

Shelly Goodin is SAS Publications' social media marketer and the editor of "SAS Publishing News". She’s worked in the publishing industry for over thirteen years, including seven years at SAS, and enjoys creating opportunities for fans of SAS and JMP software to get to know SAS Publications' many offerings and authors.

Leave A Reply

Back to Top