Improving Program Efficiency with Macro Variables |
Understanding Macro
Variables |
SAS Macro Variables
SAS macro variables are part of the macro facility, which is a tool for extending and customizing SAS software and for reducing the amount of text you must enter to complete tasks. A macro variable is independent of a SAS data set and contains one value that remains constant until you change it. The value of a macro variable is a text string that becomes part of your program whenever the macro variable is referenced. You can assign any text string to a macro variable. For example, three possible values are shown below: Region Five Tests The assigned text is then placed into your program whenever the macro variable is referenced. [Macro Variable] 1 9 9 9 . . . . . . . . . . . . . . . . title "Temporary Employees for 1999"; . . . data hrd.temp1999; . . set hrd.temp; . . if YEAR(enddate)=1999; . run; . proc print data=hrd.temp1999; run; Macro variables can be defined and referenced anywhere in a SAS program except within data lines. So, if your DATA step reads instream data, which is data included in the program, you cannot define or reference a macro variable within these lines. data site6.trial; input name $ sex $ age level1 level2; datalines; Treborn F 35 254 309 Washington M 27 198 167 Randell M 43 155 150 Farley F 60 202 210 ; run; proc print data=site6.trial; run;
There are two types of macro variables:
As these names suggest, automatic macro variables are provided by SAS software, whereas you create and define the value of user-defined macro variables. You learn more about each type of macro variable in the next two sections of this lesson. |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.