Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sentry Page Protection
Please Wait...
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. 
Picture
​
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;
Picture

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"; 
Picture

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;

Picture

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:
Picture

** 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';
Picture

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:
  • 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.
Next

Need some help? 

Get Hint
Get Solution

Fill out my online form.

Home 
​1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Summary | Final Test | Coding Exercises
Already a member? Go to member's area.