Status Variable Contains
SYSSTARTID The ID generated from the last STARTSAS
statement
SYSSTARTNAME The process name generated from the last
STARTSAS statement
SYSTCPIPHOSTNAME The host names of the local and remote operating
environments when multiple TCP/IP stacks are
supported
SYSTIME The character value of the time at which a SAS
job or session began executing
SYSTIMEZONE The time zone name based on TIMEZONE option
SYSTIMEZONEIDENT The time zone ID based on TIMEZONE option
SYSTIMEZONEOFFSET The current time zone offset based on
TIMEZONE option
SYSUSERID The user ID or login of the current SAS process
SYSVER The release or version number of SAS software
executing
SYSVLONG The release number and maintenance level of SAS
software with a 2-digit year
SYSVLONG4 The release number and maintenance level of SAS
software with a 4-digit year
SYSWARNINGTEXT Text of the last warning message formatted for
display on the SAS log
Macro Variables Defined by Users
Overview for Defining Macro Variables
You can create your own macro variables, change their values, and define their scope.
You can define a macro variable within a macro, and you can also specifically define it
as a global variable, by defining it with the %GLOBAL statement. Macro variable
names must start with a letter or an underscore and can be followed by letters or digits.
You can assign any name to a macro variable as long as the name is not a reserved word.
The prefixes AF, DMS, SQL, and SYS are not recommended because they are frequently
used in SAS software when creating macro variables. Thus, using one of these prefixes
can cause a name conflict with macro variables created by SAS software. For a complete
list of reserved words in the macro language, see Appendix 1, “ Reserved Words in the
28 Chapter 3 Macro Variables
Macro Facility,” on page 389. If you assign a macro variable name that is not valid, an
error message is printed in the SAS log.
You can use %PUT _ALL_ to view all user-created macro variables.
Creating User-Defined Macro Variable Names
The simplest way to create a user-defined macro variable is to use the macro program
statement %LET:
%let dsname=Newdata;
DSNAME is the name of the macro variable. Newdata is the value of the macro
variable DSNAME. The following are the rules for creating a macro variable:
1. SAS macro variable names can be up to 32 characters in length.
2. The first character must begin with a letter or an underscore. Subsequent characters
can be letters, numeric digits, or underscores.
3. A macro variable name cannot contain blanks.
4. A macro variable name cannot contain double-byte character set (DBCS) characters.
5. A macro variable name cannot contain any special characters other than the
underscore.
6. Macro variable names are case insensitive. For example, cat, Cat, and CAT all
represent the same variable.
7. You can assign any name to a macro variable as long as the name is not a reserved
word. The prefixes AF, DMS, SQL, and SYS are not recommended because they are
frequently used in SAS software for automatic macro variables. Thus, using one of
these prefixes can cause a name conflict with an automatic macro variable. For a
complete list of reserved words in the macro language, see Appendix 1, “ Reserved
Words in the Macro Facility,” on page 389. If you assign a macro variable name that
is not valid, an error message is printed in the SAS log.
Assigning Values to Macro Variables
The simplest way to assign a value to a macro variable is to use the macro program
statement %LET:
%let dsname=Newdata;
DSNAME is the name of the macro variable. Newdata is the value of the macro
variable DSNAME. The value of a macro variable is simply a string of characters. The
characters can include any letters, numbers, or printable symbols found on your
keyboard, and blanks between characters. The case of letters is preserved in a macro
variable value. Some characters, such as unmatched quotation marks, require special
treatment, which is described later.
If a macro variable already exists, a value assigned to it replaces its current value. If a
macro variable or its value contains macro triggers (% or &), the trigger is evaluated
before the value is assigned. In the following example, &name is resolved to Cary and
then it is assigned as the value of
city in the following statements:
%let name=Cary;
%let city=&name;
Generally, the macro processor treats alphabetic characters, digits, and symbols (except
& and %) as characters. It can also treat & and % as characters using a special treatment,
Macro Variables Defined by Users 29

Get SAS 9.4 Macro Language, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.