Names in the SAS Language


Names in the SAS Language

Definition of a SAS Name

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 variable names than for other language elements. See 'Rules for SAS Variable Names' on page 20.

  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.

  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

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

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 :

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

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

    3. A variable name cannot contain blanks.

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

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

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

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

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

    • CAUTION:

      • Available for Base SAS procedures and SAS/STAT procedures only. VALIDVARNAME=ANY has been verified for use with only Base SAS procedures and SAS/STAT procedures. Any other use of this option is considered experimental and might cause undetected errors.

    • Note: If you use any characters other than English letters, numeric digits, 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' on page 21.

    1. A variable name can contain mixed case. Mixed case is 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.

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 letter n . Name literals allow you to use special characters (or blanks) that are not otherwise allowed in SAS names. 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.

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

  • When the name literal of a DBMS table or column contains any characters that are not valid for SAS rules, then you might need to specify a SAS/ACCESS LIBNAME statement option.

  • In a quoted string, SAS preserves and uses leading blanks, but SAS ignores and trims trailing blanks.

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 .

Avoiding Errors When Using Name Literals

For information on how to avoid creating name literals in error, see 'Avoiding a Common Error With Constants' on page 115.

Examples

Examples of SAS name literals are

  • input 'Bob''s Asset Number'n;

  • input 'Bob"s Asset Number'n;

  •  libname foo  SAS/ACCESS-engine-name   SAS/ACCESS-engine-connection-options  ;  data foo.'My Table'n; 
  •  input 'Amount Budgeted'n 'Amount Spent'n        'Amount Difference'n; 



SAS 9.1 Language Reference. Concepts
SAS 9.1 Language Reference Concepts
ISBN: 1590471989
EAN: 2147483647
Year: 2004
Pages: 255

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net