|Rules for Words and Names in the SAS Language|
|Definition of a SAS Name|
|Rules for User-Supplied SAS Names|
Note: The rules are more flexible for SAS variable names than for other language elements. See Rules for SAS Variable Names.
|SAS Language Element||Maximum Length|
|DATA step statement labels||32|
|DATA step variable labels||256|
|DATA step variables||32|
|DATA step windows||32|
|Generation data sets||28|
|Members of SAS libraries (SAS data sets, SAS views, catalogs, indexes) except for generation data sets||32|
|Procedure names (first eight characters must be unique, and cannot 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 three settings (V7, UPCASE, and ANY), each with varying degrees of flexibility for variable names:
A variable name can contain mixed case. 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 lowercase and uppercase to represent different variables. For example, cat, Cat, and CAT all represent the same variable.
The name can contain special and multi-byte characters not to exceed 32 bytes.
The name cannot contain any null bytes.
A name can contain blanks. The leading blanks are preserved, but the trailing blanks are ignored.
A name must contain at least one character. A name with all blanks is not permitted.
Note: 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 you use 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.
A variable name can contain mixed-case letters. Mixed-case letters are stored and used for presentation purposes only. (SAS stores the case that is used in the first reference to a variable.) When SAS processes variable names, however, it internally uppercases them. Therefore, you cannot use the same letters with different combinations of lowercase and uppercase to represent different variables. For example, cat, Cat, and CAT all represent the same variable.
|Warning:||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. 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.|
|SAS Name Literals|
A SAS name literal is a name token that is expressed as a string within quotation marks, followed by the upper- or lowercase letter n. Name literals enable you to use special characters (including blanks) that are not otherwise allowed in SAS names when you specify a SAS data set or a variable. Blanks between the closing quotation mark and the n are not valid when you specify a name literal. When the name literal of a data set or variable contains any characters that are not allowed when VALIDVARNAME=V7, then you must set the VALIDVARNAME= system option to ANY. Note that even if you set the system option to ANY, the V6 engine does not support names that have intervening blanks.
Name literals are especially useful for expressing DBMS column and table names that contain special characters.
The following is an example of a VAR statement and a name literal:
The following is an example of a VAR statement with variables A and B:
Note: For more details about the VALIDVARNAME=ANY system option, see SAS Language Reference: Dictionary.
If you use 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.
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 for Relational Databases: Reference.
In a quoted string, SAS preserves and uses leading blanks, but SAS ignores and trims trailing blanks.
For information on how to avoid creating name literals in error, see Avoiding a Common Error with Constants.