Improving Program Efficiency with Macro Variables |
Using Automatic Macro
Variables |
This section teaches you how to use automatic macro variables in your
programs. After completing this section, you will be able to
Whenever you invoke the SAS System, automatic macro variables are created that provide such information as the
To demonstrate how to use automatic macro variables, let's modify the following program to include an automatic macro variable. This program creates and prints a data set that has information about temporary employees who were hired in November. title 'Temporary Employees Hired in November'; data hrd.tempnov; set hrd.temp; if month(begindate)=11; run; proc print data=hrd.tempnov; run;
The program includes the MONTH function to extract the month value from the
data set variable
The automatic macro variable SYSDATE can provide the date that the program is executed. The SYSDATE macro variable supplies the date when a SAS job began executing or when you began your SAS session. The date is displayed by using the DATE7. format. For example, in a job that begins executing on November 30, 1999, the value of SYSDATE is 30NOV99. You can include this date in the footnote of your report by referencing the SYSDATE macro variable in the FOOTNOTE statement. To reference any macro variable, you specify the macro variable name preceded by an ampersand. &SYSDATE So, you write the FOOTNOTE statement as follows: footnote "Report Run on &sysdate";
Prior to DATA step compilation, SAS software resolves the macro variable
reference by replacing So your FOOTNOTE statement . . . footnote "Report Run on &sysdate"; . . . is processed as follows, if your session begins on November 30, 1999: footnote "Report Run on 30NOV99"; Then, after your program compiles successfully, the program statements are executed, and your new data set is printed with the specified title and footnote. |
Obs | Agency | ID | Name |
1 | F274 | Cichock, Elizabeth Marie | |
2 | OD Consulting, Inc. | F054 | Shere, Brian Thomas |
3 | Administrative Support, Inc. | P039 | Chevarley, Arlene Elsie |
4 | New Time Temps Agency | P378 | Bates, Ellen Marie |
5 | Temporary Services, Inc. | F462 | |
6 | Administrative Support, Inc. | F015 | Lamutu, Julie Hope |
7 | New Time Temps Agency | F524 | Abramson, Andrea Carlson |
8 | Administrative Support, Inc. | F029 | Kling, Meredith Ann |
9 | Administrative Support, Inc. | P256 | Clough, Patricia Lee |
10 | Temporary Services, Inc. | P275 | Albritton, Brian Mark |
11 | All Temps | F153 | Wingo, Jennifer Marie |
12 | OD Consulting, Inc. | F187 | May, Rodney John |
13 | Administrative Support, Inc. | F300 | Smith, Jack Kenneth |
14 | All Temps | P136 | Sukensis, Valerie Rush |
15 | Temporary Services, Inc. | F170 | Howell, Jody Pierre |
16 | Temporary Services, Inc. | F381 | Harrell, Kenneth Lee |
17 | OD Consulting, Inc. | F112 | Chu, Judi Christine |
18 | OD Consulting, Inc. | F194 | Kempster, Robin Lynn |
19 | OD Consulting, Inc. | P182 | Hickel, Dawn Elizabeth |
20 | Administrative Support, Inc. | P090 | Connick, Patricia Ann |
21 | All Temps | P244 | Patterson, Gregory John |
Report Run on 30NOV99 |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.