Rules for Words and Names 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:
consists of 1 to 32,767 characters enclosed in single or double quotation marks. Here are some examples of literals:
Note: The surrounding quotation marks identify the token as a literal, but SAS does not store these marks as part of the literal token.
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:
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 |
You can begin SAS statements in any column of a line and write several statements on the same line.
You can begin a statement on one line and continue it on another line, but you cannot split a word between two lines.
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.
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.
In this statement, blanks are not required because SAS can determine the boundary of every token by examining the beginning of the next token:
total=x+y;
The first special-character token, the equal sign, marks the end of the name token total. The plus sign, another special-character token, marks the end of the name token x. The last special-character token, the semicolon, marks the end of the y token. Though blanks are not needed to end any tokens in this example, you can add them for readability, as shown here:
total = x + y;
This statement requires blanks because SAS cannot recognize the individual tokens without them:
input group 15 room 20;
Without blanks, the entire statement up to the semicolon fits the rules for a name token: it begins with a letter or underscore, contains letters, digits, or underscores thereafter, and is less than 32,767 characters long. Therefore, this statement requires blanks to distinguish individual name and number tokens.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.