Previous Page | Next Page

Rules for Words and Names in the SAS Language

Names in the SAS Language


Definition of a SAS Name

A SAS name is a name token that represents

There are two types of names in SAS:


Rules for User-Supplied SAS Names


Rules for Most SAS Names

Note:   The rules are more flexible for SAS variable names than for other language elements. See Rules for SAS Variable Names.  [cautionend]

Maximum Length of User-Supplied SAS Names
SAS Language Element Maximum Length
Arrays 32
CALL routines 16
Catalog entries 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
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 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:

V7

is the default setting.

Variable name rules are as follows:

  • SAS variable names can be up to 32 characters in length.

  • The first character must begin with an English letter or an underscore. Subsequent characters can be English letters, numeric digits, or underscores.

  • A variable name cannot contain blanks.

  • A variable name cannot contain any special characters other than the underscore.

  • 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.

  • You do 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 V7, except that variable names are uppercased, as in earlier versions of SAS.

ANY

  • SAS variable names can be up to 32 characters in length.

  • 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.

  • The name can start with or contain any characters, including blanks.

    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.  [cautionend]

  • 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


Definition of 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:

var 'a b'n;

The following is an example of a VAR statement with variables A and B:

var a b;


Important Restrictions


Avoiding Errors When Using Name Literals

For information on how to avoid creating name literals in error, see Avoiding a Common Error with Constants.


Examples

Examples of SAS name literals are

Previous Page | Next Page | Top of Page