Improving Program Efficiency with Macro Variables |
Creating Your Own Macro
Variables![]() ![]() |
Combining Macro Variable References with Suffixes
You can also combine macro variable references with suffixes. For example,
the subsetting IF statement in this DATA step uses the YEAR function to extract
the year value from the data set variable %let yr=1999; title "Temporary Employees for &yr"; data hrd.temp&yr; set hrd.temp; if year(enddate)=&yr; run; proc print data=hrd.temp&yr; run;
Sometimes, however, you need to run this program using the data set variable
%let yr=1999; title "Temporary Employees for &yr"; data hrd.temp&yr; set hrd.temp; if year(begindate)=&yr; run; proc print data=hrd.temp&yr; run;
You can create a macro variable to easily change the beginning or ending
date variable throughout the program. You create a macro variable named
Then you reference the macro variable in the subsetting IF statement and
concatenate the suffix |
![]() |
When combining a macro variable prefix and a suffix, you must separate them with a period. SAS software has no way of knowing where you macro variable reference ends and the suffix begins if you don't separate them with a period. |
When the IF statement resolves, SAS software reads
&period as the macro variable reference. Then it replaces
the reference with the value of period to create the variable
name EndDate .
The program looks like this: %let yr=1999; %let period=end; title "Temporary Employees for &yr"; data hrd.temp&yr; set hrd.temp; if year(&period.date)=&yr; run; proc print data=hrd.temp&yr; run; |
![]() ![]() ![]() ![]() ![]() ![]() |
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.