Three reasons to learn SAS macro facility

3

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:

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

Share

About Author

Michele Burlew

Michele Burlew designs and programs SAS applications for data management, data analysis, report writing, and graphics for academic and corporate clients. A SAS user since 1980, she’s the author of several popular SAS books including: SAS Macro Programming Made Easy, Third Edition, SAS Hash Object Programming Made Easy, Combining and Modifying SAS Data Sets: Examples, Second Edition, Output Delivery System: The Basics and Beyond (coauthor), SAS Guide to Report Writing: Examples, Second Edition, Debugging SAS Programs: A Handbook of Tools and Techniques, and Reading External Data Files Using SAS: Examples Handbook.

3 Comments

  1. Jim Sattler on

    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.

  2. 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.

Back to Top