Using Macro Variables

Using User-Defined Macro Variables

%LET Statement Syntax

Use the %LET statement to define your macro variable and assign a value to it.
Syntax, %LET statement:
%LET variable=value;
variable
is any name that follows the SAS naming convention.
value
can be any string from 0 to 65,534 characters long.
Note: If the variable already exists, then the value replaces the current value. If either variable or value contains a reference to another macro variable (such as &macvar), the reference is evaluated before the assignment is made.

Using Automatic Macro Variables

What Are Automatic Macro Variables?

SAS creates and defines several automatic macro variables for you. Automatic macro variables contain information about your computing environment, such as the date and time of the session, and the version of SAS that you are running. Keep the following facts in mind about these automatic macro variables:
  • They are created when SAS starts.
  • They are global (always available).
  • They are usually assigned values by SAS.
  • They can be assigned values by the user in some cases.
Some automatic macro variables have fixed values that are set when SAS starts.
Name
Value
SYSDATE
the date of the SAS invocation (DATE7.)
SYSDATE9
the date of the SAS invocation (DATE9.)
SYSDAY
the day of the week of the SAS invocation
SYSTIME
the time of the SAS invocation
SYSENV
FORE (interactive execution) or BACK (noninteractive or batch execution)
SYSSCP
an abbreviation for the operating system that is being used, such as WIN or LINUX
SYSVER
the release of SAS that is being used
SYSJOBID
an identifier for the current SAS session or for the current batch job (the user ID or job name for mainframe systems, the process ID (PID) for other systems)
Some automatic macro variables have values that automatically change based on submitted SAS statements.
Name
Value
SYSLAST
the name of the most recently created SAS data set, in the form LIBREF.NAME. This value is always stored in all capital letters. If no data set has been created, the value is _NULL_.
SYSPARM
text that is specified when SAS starts.
SYSERR
contains a return code status that is set by the DATA step and some SAS procedures to indicate whether the step or procedure executed successfully.

Example: Using Automatic Macro Variables

You can substitute system information such as the time, day, and date on which your SAS session started in footnotes for a report.
footnote1 "Created &systime &sysday, &sysdate9";
title "MPG City Over 25";
proc print data=sashelp.cars;
   var Make Model Type MPG_City MPG_Highway MSRP;
   where MPG_City>25;
run;
Output 7.1 PROC PRINT Output of Automatic Macro Variables
PROC PRINT Output of Automatic Macro Variables
1 time of day (SYSTIME)
2 day of the week (SYSDAY)
3 date (day, month, and year) (SYSDATE9)
Last updated: October 16, 2019
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.98.166