People tend to think of the SAS macro facility as something to tackle when you’ve reached ‘advanced programmer’ status. But macro programming can be easy to learn, and it allows you to work faster and more effectively.
Here are three reasons why you should consider learning the macro facility, even if, or perhaps especially if, you’re a beginning SAS programmer:
- When you use the macro facility, you can accomplish repetitive tasks quickly and efficiently. A macro program can be reused many times. Parameters passed to a macro program customize the results without having to change the code within the macro program.
- Macro programming can provide a more modular structure to your SAS programs. SAS language that is repetitive can be generated by macro language statements in a macro program and that macro program can be referenced in your SAS program. The main program becomes easier to read – especially if you give the macro program a meaningful name for the task it performs.
- A more detailed reason is that it makes it much easier to pass information between steps. For example, a PROC SQL step can summarize data and save results in macro variables. These macro variables can then be used by subsequent DATA steps and PROC steps in the same SAS session to customize the processing.
And a bonus reason – most SAS programming job descriptions ask for applicants with macro programming experience. My latest book SAS Macro Programming Made Easy, Third Edition will start you down the path to obtaining that required experience.
3 Comments
Michele, what you call a "detailed reason" introduces the true benefit of learning macro programming. In a word, macro programming facilitates automation. At an advanced level, macro programming makes it possible to build table-driven applications in which macros manage how to generate code. The technique of table-driven applications is still a professional programmer's secret - unfortunately. Likewise, the existing macro courses only hint at what can be done with macro=managed code generation and supply only simple examples.
Time flies! although I am using SAS 9.4, your first printing (November, 1998) of "SAS Macro Programming Made Easy" is still one of my office desk reference books.
Thanks, Ji-Ping, for reading my book!