A SAS name is a name token that represents
- variables
- SAS data sets
- formats or
informats
- SAS
procedures
- options
- arrays
- statement
labels
- SAS macros or macro variables
- SAS catalog entries
- librefs or
filerefs.
There are two kinds of names in SAS:
- names of elements of the SAS
language
- names supplied by SAS users.
|
Rules for User-Supplied SAS Names |
Rules for Most SAS Names
Note: The rules are more flexible for SAS variables names than
for other language elements. See Rules for SAS Variable Names.
- The length of a SAS
name depends on the element it is assigned
to. Many SAS names can be 32 characters long; others have a maximum length
of 8. The notable exception is user-written informats, which have a maximum
length of 7. See Maximum Length of User-Supplied SAS Names.
- The first character must be a letter (A, B, C, . . ., Z) or
underscore
(_). Subsequent characters can be letters, numeric digits (0, 1, . . ., 9),
or underscores.
- You can use upper or lowercase letters. SAS processes names as
uppercase regardless of how you type them.
- Blanks cannot appear in SAS names.
- Special characters, except for the
underscore, are not allowed.
In filerefs only, you can use the dollar sign ($), pound sign (#), and at
sign (@).
- SAS reserves a few names for automatic variables and variable
lists, SAS data sets, and librefs.
- When creating variables, do not use the names of special SAS automatic
variables (for example, _N_ and _ERROR_) or special variable list names (for
example, _CHARACTER_, _NUMERIC_, and _ALL_).
- When associating a libref with a SAS data library, do not use
these:
| SASHELP |
| SASMSG |
| SASUSER |
| WORK |
- When
you create SAS data sets, do not use these names:
- When
assigning a fileref to an external file, do not use:
- When you create a macro variable, do not use names that begin
with
SYS
.
Maximum Length of User-Supplied SAS Names
SAS Language Element |
Maximum Length |
Members of SAS data libraries (SAS data sets, views, catalogs,
indexes) except for generation data sets |
32 |
Generation data sets |
28 |
Catalog entries |
32 |
Engines |
8 |
Librefs |
8 |
Filerefs |
8 |
Passwords |
8 |
DATA step variables |
32 |
DATA step variable labels |
256 |
DATA step statement labels |
32 |
Arrays |
32 |
DATA step windows |
32 |
Functions |
16 |
CALL routines |
16 |
Formats |
8 |
Informats |
7 |
Macros |
32 |
Macro variables |
32 |
Macro windows |
32 |
SCL variables |
32 |
SAS/EIS items |
depends on the data dictionary |
Procedure names (First 8 characters must be unique, and may not begin
with "SAS".) |
16 |
The rules for SAS variable names have expanded to provide more functionality.
The setting of the VALIDVARNAME= system option determines what rules apply
to the variables that you can create and process in your SAS session as well
as to variables that you want to read from existing data sets. The VALIDVARNAME=
option has four settings (V7, UPCASE, V6 and ANY), each with varying degrees
of flexibility for variable names:
- V7
- is the default setting for Version 7.
Variable name rules for Version 7 are as follows:
- SAS
variable names may be up to 32 characters in length.
- The first character must begin with an alphabetic character or
an underscore. Subsequent characters can be alphabetic characters, numeric
digits, or underscores.
- A variable name may not contain blanks.
- A variable name may not contain any special characters
other than
the underscore.
- A variable name may contain mixed case. The mixed case is remembered
and used for presentation purposes only. (SAS stores the case used in the
first reference to a variable.) When SAS processes variable names, however,
it internally uppercases them. You cannot, therefore, use the same letters
with different combinations of lower- and uppercase to represent different
variables. For example,
cat
, Cat
, and CAT
all represent
the same variable.
- You may not assign the names of special SAS automatic variables
(such as _N_ and _ERROR_) or variable list names (such as _NUMERIC_, _CHARACTER_,
and _ALL_) to variables.
- UPCASE
- is the same as when VALIDVARNAME=V7, except that variable
names are uppercased, as in earlier versions of SAS software.
- V6
- is the same as when VALIDVARNAME=V7, except
that variable names are uppercased and they may be only 8 characters long,
as in earlier versions of SAS software.
- CAUTION:
- Transitional use only:
VALIDVARNAME=V6
is intended for transitional use only. Use this option for applications that
you need to use under both Version 6 and Version 7 of the SAS System.
- CAUTION:
- May render some applications unusable:
Using VALIDVARNAME=V6
may render some Version 7 macros or Version 7 SAS/AF
applications unusable.
- ANY
-
- SAS variable names may be up to 32 characters in length.
- The name may start with
or contain any characters, including blanks.
Note: If you use any characters other the ones that are valid when VALIDVARNAME=V7
(letters, numeric digits, or underscores), then you must express the variable
name as a name literal and you must set VALIDVARNAME=ANY. See
SAS Name Literals.
- A variable name may contain mixed case. The mixed case is remembered
and used for presentation purposes only. (SAS stores the case used in the
first reference to a variable.) When SAS processes variable names, however,
it internally uppercases them. You cannot, therefore, use the same letters
with different combinations of lower- and uppercase to represent different
variables. For example,
cat
, Cat
, and CAT
all represent
the same variable.
Definition
A SAS name literal is a name token that is
expressed as a string within quotation marks, followed by the letter n. Name literals allow you to use special characters (or blanks) that
are not otherwise allowed in SAS names when you specify a SAS data set or
a variable. Name literals are especially useful for expressing DBMS column
and table names that contain special characters.
Important Restrictions
- You can use a name literal only for variables, statement labels,
and DBMS column and table names.
- You can use name literals in a DATA step or a PROC SQL step only.
- When the name
literal of a variable or DBMS column contains any
characters that are not allowed when VALIDVARNAME=V7, then you must set the
system option VALIDVARNAME=ANY.
- When the name literal of a DBMS table or column contains any characters
not allowed by SAS rules for names, then you may need to specify a SAS/ACCESS
LIBNAME statement option.
Note: For more details and examples about the SAS/ACCESS LIBNAME statement
and about using DBMS table and column names that do not conform to SAS naming
conventions, see SAS/ACCESS Software for Relational Databases: Reference.
Examples
Examples of SAS name literals are
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.