SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Improving Program Efficiency with Macro Variables
Understanding Macro Variables


This section introduces you to the function of SAS macro variables. After completing this section, you will be able to
  • identify when to include a macro variable in a SAS program
  • identify the different types of macro variables.

When writing your SAS programs, you may find that you need to reference the same variable, data set, or text string several times in the same program.

     title "Temporary Employees for 1999";
     data hrd.temp1999;
        set hrd.temp;
        if year(enddate)=1999;
     run;
     proc print data=hrd.temp1999;
     run;

Then, you may need to change these multiple references so you can run your program using a new variable, data set, or text string. Scanning your program and manually changing multiple references may require a great deal of time, especially if your program is lengthy.

     title "Temporary Employees for 2000";
     data hrd.temp2000;
        set hrd.temp;
        if year(enddate)=2000;
     run;
     proc print data=hrd.temp2000;
     run;

Using SAS macro variables simplifies the process of editing multiple references in programs. Macro variables substitute text in programs so you can make one change and have the change appear throughout the program. Let's see how macro variables work.


back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement