Previous Page | Next Page

Rules for Words and Names in the SAS Language

Words in the SAS Language

Definition of Word

A word or token in the SAS programming language is a collection of characters that communicates a meaning to SAS and which cannot be divided into smaller units that can be used independently. A word can contain a maximum of 32,767 characters.

A word or token ends when SAS encounters one of the following:

Each word or token in the SAS language belongs to one of four categories:

Types of Words or Tokens

There are four basic types of words or tokens:


is a series of characters that begin with a letter or an underscore. Later characters can include letters, underscores, and numeric digits. A name token can contain up to 32,767 characters. In most contexts, however, SAS names are limited to a shorter maximum length, such as 32 or 8 characters. See Maximum Length of User-Supplied SAS Names. Here are some examples of name tokens:

  • data
  • _new
  • yearcutoff
  • year_99
  • descending
  • _n_

consists of 1 to 32,767 characters enclosed in single or double quotation marks. Here are some examples of literals:

  • 'Chicago'
  • "1990-91"
  • 'Amelia Earhart'
  • 'Amelia Earhart''s plane'
  • "Report for the Third Quarter"

Note:   The surrounding quotation marks identify the token as a literal, but SAS does not store these marks as part of the literal token.  [cautionend]


in general, is composed entirely of numeric digits, with an optional decimal point and a leading plus or minus sign. SAS also recognizes numeric values in the following forms as number tokens: scientific (E-) notation, hexadecimal notation, missing value symbols, and date and time literals. Here are some examples of number tokens:

  • 5683
  • 2.35
  • 0b0x
  • -5
  • 5.4E-1
  • '24aug90'd
special character

is usually any single keyboard character other than letters, numbers, the underscore, and the blank. In general, each special character is a single token, although some two-character operators, such as ** and <=, form single tokens. The blank can end a name or a number token, but it is not a token. Here are some examples of special-character tokens:

  • =
  • ;
  • '
  • +
  • @
  • /

Placement and Spacing of Words in SAS Statements

Spacing Requirements

  1. You can begin SAS statements in any column of a line and write several statements on the same line.

  2. You can begin a statement on one line and continue it on another line, but you cannot split a word between two lines.

  3. A blank is not treated as a character in a SAS statement unless it is enclosed in quotation marks as a literal or part of a literal. Therefore, you can put multiple blanks any place in a SAS statement where you can put a single blank, with no effect on the syntax.

  4. The rules for recognizing the boundaries of words or tokens determine the use of spacing between them in SAS programs. If SAS can determine the beginning of each token due to cues such as operators, you do not need to include blanks. If SAS cannot determine the beginning of each token, you must use blanks. See Examples.

Although SAS does not have rigid spacing requirements, SAS programs are easier to read and maintain if you consistently indent statements. The examples illustrate useful spacing conventions.


Previous Page | Next Page | Top of Page