Overview Section
This lesson introduces the most commonly used features of the SAS macro language. When you write a program that will be run over and over again, you might want seriously to consider using "macros" in your code, because:
- macros allow you to make a change in one location of your program so that SAS can cascade the change throughout your program
- macros allow you to write a section of code once and use it over and over again, in the same program or even different programs
- macros allow you to make programs data-driven, letting SAS decide what to do based on actual data values.
To whet our appetite for SAS macros, we'll read this paper:
SAS Macro Programming for Beginners
written by Susan J. Slaughter and Lora D. Delwiche and presented as a tutorial at the 2004 SAS Users Group International (SUGI) Meeting in Montreal, Canada.
Objectives
Upon completion of this lesson, you should be able to:
- understand what a SAS macro is
- distinguish between local and global macro variables
- create a macro variable using a %LET assignment statement
- use a macro variable in a SAS program
- write and invoke a basic SAS macro
- write and invoke a SAS macro that uses parameters
- write a macro with conditional macro %IF-%THEN-%ELSE statements
- use and understand automatic macro variables such as &SYSDATE and &SYSDAY
- use CALL SYMPUT to write data-driven programs
Textbook Reference Section
SAS Macro Programming for Beginners paper written by Susan J. Slaughter and Lora D. Delwiche.