Sentry Page Protection
SAS Macro [2-15]
Automatic Macro Variables
Automatic macro variables are the built-in macro variables that can automate and enhance your program.
Example
Copy and run the TRANSAC data set from the yellow box below.
Example
Copy and run the TRANSAC data set from the yellow box below.
The TRANSAC data set contains a list of transactions, agents and transaction amount:
The TRANSAC data set contains a list of transactions, agents and transaction amount:
- TranID: Transaction ID
- Agent: Tom, Mary or John
- Amount: Transaction Amount
&Sysdate, &Systime
Let's assume you have to run a summary report for the transaction amount everyday.
You could write a program that includes the date and time of the report in the title:
Example
Title1 "Transaction Report";
Title2 "May 8 at 12:10pm";
proc means data=transac N Mean STD;
var amount;
class agent;
run;
Let's assume you have to run a summary report for the transaction amount everyday.
You could write a program that includes the date and time of the report in the title:
Example
Title1 "Transaction Report";
Title2 "May 8 at 12:10pm";
proc means data=transac N Mean STD;
var amount;
class agent;
run;
The program looks good. However, if you are going to reuse the program on a daily basis, you will have to manually change the date and time in the title statement:
Example
Title2 "May 8 at 12:10pm";
A better way to write the program is to use the automatic macro variables:
- Sysdate
- Systime
Sysdate and Systime are two built-in macro variables that contain the date and time of the current SAS sessions.
Example
Title1 "Transaction Report";
Title2 "&sysdate at &systime";
proc means data=transac N Mean STD;
var amount;
class agent;
run;
The macro variable sysdate and systime will be replaced by the date and time of the current SAS session, respectively.
The date and time of the report will be automatically updated:
** Important Note **
When referencing a macro variable within a quotation, double quotes must be used.
Example
Good
Title2 "&sysdate at &systime";
Bad
Title2 '&sysdate at &systime';
SAS does not recognize macro variables within a single quote.
Example
Title1 'Transaction Report';
Title2 '&sysdate at&systime';
In later sessions, you will learn how to change the display format of the macro variables using SAS macro functions.
Exercise
Some other common automatic macro variables include:
Rerun the program above and add two footnotes to the program:
where xxx = operating system and yyy = SAS version.
Some other common automatic macro variables include:
- Sysscp: Operating System being used
- Sysver: SAS version being used
Rerun the program above and add two footnotes to the program:
- Footnote 1: Operating System: xxx
- Footnote 2: SAS Version: yyy
where xxx = operating system and yyy = SAS version.
Need some help?
Fill out my online form.