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 391. 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 391. 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
which is described later. It does not make a distinction between character and numeric
values as the rest of SAS does. (However, the “%EVAL Function” on page 261 and
“%SYSEVALF Function” on page 281 can evaluate macro variables as integers or
floating point numbers.)
Macro variable values can represent text to be generated by the macro processor or text
to be used by the macro processor. Values can range in length from 0 to 65,534
characters. If you omit the value argument, the value is null (0 characters). By default,
leading and trailing blanks are not stored with the value.
In addition to the %LET statement, the following list contains other features of the
macro language that create macro variables:
iterative %DO statement
%GLOBAL statement
%INPUT statement
INTO clause of the SELECT statement in SQL
%LOCAL statement
%MACRO statement
SYMPUT and SYMPUTX routine and SYMPUTN routine in SCL
%WINDOW statement
The following table describes how to assign a variety of types of values to macro
variables.
Table 3.2 Types of Assignments for Macro Variable Values
Assign Values
Constant text A character string. The following statements show several ways that the
value maple can be assigned to macro variable STREET. In each case, the
macro processor stores the five-character value maple as the value of
STREET. The leading and trailing blanks are not stored.
%let street=maple;
%let street= maple;
%let street=maple ;
Note: Quotation marks are not required. If quotation marks are used, they
become part of the value.
Digits The appropriate digits. This example creates the macro variables NUM and
TOTALSTR:
%let num=123;
%let totalstr=100+200;
The macro processor does not treat 123 as a number or evaluate the
expression 100+200. Instead, the macro processor treats all the digits as
characters.
30 Chapter 3 Macro Variables
Assign Values
Arithmetic
expressions
The %EVAL function, for example,
%let num=%eval(100+200); / * produces 300 * /
use the %SYSEVALF function, for example,
%let num=%sysevalf(100+1.597); / * produces 101.597 * /
For more information, see “Macro Evaluation Functions” on page 162.
A null value No assignment for the value argument, for example,
%let country=;
A macro
variable
reference
A macro variable reference, &macro-variable. For example,
%let street=Maple;
%let num=123;
%let address=&num &street Avenue;
This example shows multiple macro references that are part of a text
expression. The macro processor attempts to resolve text expressions before
it makes the assignment. Thus, the macro processor stores the value of
macro variable ADDRESS as 123 Maple Avenue.
You can treat ampersands and percent signs as literals by using the
%NRSTR function to mask the character. This causes the macro processor
to treat it as text instead of trying to interpret it as a macro call. For more
information, see Chapter 12, “Macro Language Elements,” on page 157 and
Macro Quoting on page 82.
A macro
invocation
A macro call, %macro-name. For example,
%let status=%wait;
When the %LET statement executes, the macro processor also invokes the
macro WAIT. The macro processor stores the text produced by the macro
WAIT as the value of STATUS.
To prevent the macro from being invoked when the %LET statement
executes, use the %NRSTR function to mask the percent sign:
%let status=%nrstr(%wait);
The macro processor stores %wait as the value of STATUS.
Macro Variables Defined by Users 31
..................Content has been hidden....................

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