Chapter Contents

Previous

Next

Names in the SAS Language


Definition

A SAS name is a name token that represents

There are two kinds of names in SAS:


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

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

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

  3. You can use upper or lowercase letters. SAS processes names as uppercase regardless of how you type them.

  4. Blanks cannot appear in SAS names.

  5. Special characters, except for the underscore, are not allowed. In filerefs only, you can use the dollar sign ($), pound sign (#), and at sign (@).

  6. SAS reserves a few names for automatic variables and variable lists, SAS data sets, and librefs.
    1. 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_).

    2. When associating a libref with a SAS data library, do not use these:
      SASHELP
      SASMSG
      SASUSER
      WORK

    3. When you create SAS data sets, do not use these names:
      _NULL_
      _DATA_
      _LAST_

  7. When assigning a fileref to an external file, do not use:
    SASCAT

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


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

  1. SAS variable names may be up to 32 characters in length.

  2. The first character must begin with an alphabetic character or an underscore. Subsequent characters can be alphabetic characters, numeric digits, or underscores.

  3. A variable name may not contain blanks.

  4. A variable name may not contain any special characters other than the underscore.

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

  6. 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.  [cautionend]
CAUTION:
May render some applications unusable: Using VALIDVARNAME=V6 may render some Version 7 macros or Version 7 SAS/AF applications unusable.  [cautionend]

ANY
  1. SAS variable names may be up to 32 characters in length.

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

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


SAS Name Literals

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

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

Examples

Examples of SAS name literals are


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.