Names in the SAS Language
Definition of a SAS Name
A SAS name is a name token that represents one of the following SAS language
elements:
variable
data set
format
informat
procedure
option
statement label
libref or fileref
catalog entry
array
macro or macro variable
component object
There are two types of names in SAS:
SAS language element names (system-supplied names)
user-supplied names
The following sections will discuss user-supplied SAS names.
Rules for User-Supplied SAS Names
Rules for Most SAS Names
The following list contains the rules that you use when you create most SAS names:
Note: The rules are more flexible for SAS variable names, data set names, view names,
and item store names than for other language elements. See “Rules for SAS Variable
Names” on page 26 and “Rules for SAS Data Set Names, View Names, and Item
Store Names” on page 27.
The length of a SAS name depends on which element it is assigned to. Many SAS
names can be 32 bytes long; others have a maximum length of 8 bytes. For a list of
SAS names and their maximum length, see Table 3.1 on page 25.
The first character must be an English letter (A, B, C, . . ., Z) or underscore (_).
Subsequent characters can be letters, numeric digits (0, 1, . . ., 9), or underscores.
You can use uppercase or lowercase letters.
Blanks cannot appear in SAS names.
Special characters, except for the underscore, are not allowed. In filerefs only, you
can use the dollar sign ($), the number sign (#), and the 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 library, do not use these libref names:
Sashelp
24 Chapter 3 Rules for Words and Names in the SAS Language
Sasmsg
Sasuser
Work
When you create SAS data sets, do not use these names:
_NULL_
_DATA_
_LAST_
When assigning a fileref to an external file, do not use the filename SASCAT.
When you create a macro variable, do not use names that begin with SYS.
Table 3.1 Maximum Length in Bytes of User-Supplied SAS Names
User-Supplied SAS Name Maximum Length in Bytes
Arrays 32
CALL routines 16
Catalog entries 32
Component objects 32
DATA step statement labels 32
DATA step variable labels 256
DATA step variables 32
DATA step windows 32
Engines 8
Filerefs 8
Formats, character 31
Formats, numeric 32
Functions 16
Generation data sets 28
Informats, character 30
Informats, numeric 31
Librefs 8
Macro variables 32
Names in the SAS Language 25
User-Supplied SAS Name Maximum Length in Bytes
Macro windows 32
Macros 32
Members of SAS libraries (SAS data sets, SAS views,
catalogs, indexes) except for generation data sets
32
Passwords 8
Procedure names (first eight characters must be unique and
cannot begin with “SAS”)
16
SCL variables 32
Rules for SAS Variable Names
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 create in your SAS session as well as to variables that you want to
read from existing data sets.
The VALIDVARNAME= option has three settings (V7, UPCASE, and ANY), each with
varying degrees of flexibility for variable names. If you do not specify the
VALIDVARNAME option in your SAS session, the default value, V7, is automatically
assigned to your SAS session. The following table summarizes the rules for variable
names when using the VALIDVARNAME system option:
V7
is the default setting.
Variable name follows these rules:
The name can be up to 32 bytes in length.
The name can contain letters of the Latin alphabet, numerals, or underscores.
The name cannot contain blanks or special characters except for the underscore.
The name must begin with a letter of the Latin alphabet (A–Z, a–z) or the
underscore.
Trailing blanks are ignored. The name alignment is left-justified.
The name can contain mixed–case letters. SAS stores and writes the variable
name in the same case that is used in the first reference to the variable. However,
when SAS processes variable names, SAS internally converts it to uppercase.
You cannot, therefore, use the same variable name with a different combination
of upper and lowercase letters to represent different variables. For example, cat,
Cat, and CAT all represent the same variable.
Do not assign variables the names of special SAS automatic variables (such as
_N_ and _ERROR_) or variable list names (such as _NUMERIC_,
_CHARACTER_, and _ALL_) to variables.
Examples
season=’summer’;
percent_of_profit=percent;
26 Chapter 3 Rules for Words and Names in the SAS Language
UPCASE
is the same as V7, except that variable names are uppercased, as in earlier versions of
SAS.
ANY
The name can be up to 32 bytes in length.
The name can contain any characters, including blanks, national characters,
special characters, and multi-byte characters. Names containing these types of
characters must be specified as name literals on page 31.
The name can begin with any characters, including blanks, national characters,
special characters, and multi-byte characters.
The name cannot contain any null bytes.
Leading blanks are preserved but trailing blanks are ignored.
The name must contain at least one character. A name with all blanks is not
permitted.
can contain mixed-case letters. SAS stores and writes the variable name in the
same case that is used in the first reference to the variable. However, when SAS
processes a variable name, SAS internally converts it to uppercases. You cannot,
therefore, use the same variable name with a different combination of uppercase
and lowercase letters to represent different variables. For example, cat, Cat,
and
CAT all represent the same variable.
Requirement
If you use any characters other than the ones that are valid when the
VALIDVARNAME= system option is set to V7 (letters of the Latin
alphabet, numerals, or underscores), then you must express the
variable name as a name literal and you must set
VALIDVARNAME=ANY. If the name includes either the percent
sign (%) or the ampersand (&), then you must use single quotation
marks in the name literal in order to avoid interaction with the SAS
Macro Facility. See “SAS Name Literals” on page 31 and
“Avoiding Errors When Using Name Literals” on page 33.
See
“How Many Characters Can I Use When I Measure SAS Name
Lengths in Bytes?” on page 30
Examples
Variable name containing blanks expressed as a name literal:
‘% of profit’n=percent;
Variable name containing a special character expressed as a name
literal:
‘items@warehouse’n=itemnum;
CAUTION
Throughout SAS, using the name literal syntax with variable
names that exceed the 32-byte limit or have excessive embedded
quotation marks might cause unexpected results. The intent of the
VALIDVARNAME=ANY system option is to enable compatibility
with other DBMS variable (column) naming conventions, such as
allowing embedded blanks and national characters.
Rules for SAS Data Set Names, View Names, and Item Store Names
Three types of SAS members, SAS data sets, data views, and item stores, are expanded
to have more functionality. The setting of the VALIDMEMNAME= system option
determines what rules apply to the names of these members in your SAS session. The
Names in the SAS Language 27
VALIDMEMNAME= option has two settings (COMPATIBLE and EXTEND), each
with varying degrees of flexibility for data set names, data view names, and item store
names:
COMPATIBLE
specifies that a SAS data set name, a view name, or an item store name must follow
these rules:
The name can be up to 32 bytes in length.
The name must begin with a letter of the Latin alphabet (A–Z, a–z) or the
underscore. Subsequent characters can be letters of the Latin alphabet, numerals,
or underscores.
The name cannot contain blanks or special characters except for the underscore.
The name can contain mixed-case letters. SAS internally converts the member
name to uppercase. You cannot, therefore, use the same member name with a
different combination of uppercase and lowercase letters to represent different
variables. For example, customer, Customer, and CUSTOMER all represent the
same member name. How the name on the disk appears is determined by the
operating environment.
Alias
COMPAT
EXTEND
specifies that a SAS data set name, a SAS view name, or an item store name must
follow these rules:
The name can be up to 32 bytes in length.
The name can include national characters, but it must be written as a SAS name
literal on page 31.
The name can include special characters, except for the / * ? " < > |: -
characters, but it must be written as a SAS name literal.
Note: The SPD engine does not allow ‘.’ (the period) anywhere in the member
name.
The name must contain at least one character (letters, numbers, valid special
characters, and national characters).
Null bytes are not allowed.
The name cannot begin with a blank or a ‘.’ (the period).
Note: The SPD engine does not allow ‘$’ as the first character of the member
name.
Leading and trailing blanks are deleted when the member is created.
The name can contain mixed-case letters. SAS internally converts the member
name to uppercase. You cannot, therefore, use the same member name with a
different combination of uppercase and lowercase letters to represent different
variables. For example, customer, Customer, and CUSTOMER all represent the
same member name. How the name appears is determined by the operating
environment.
Restrictions
Regardless of the value of VALIDMEMNAME, a member name
cannot end in the special character # followed by three digits. This
is because it would conflict with the naming conventions for
generation data sets. Using such a member name results in an error.
28 Chapter 3 Rules for Words and Names in the SAS Language
..................Content has been hidden....................

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