A word
or token in the SAS language is a collection
of characters that communicates a meaning to SAS and is not divisible into
smaller units capable of independent use. It can contain a maximum of 32,767
characters.
A word or token ends when SAS encounters one of the following:
- the beginning of a new
token
- a blank after a name or a number token
- the ending quotation mark of a literal
token.
Each word or token in the SAS language belongs to one of four categories:
- names
- literals
- numbers
- special
characters.
There are four basic types of words or
tokens:
- name
- 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.
Examples of name tokens include:
-
data
-
_new
-
yearcutoff
-
year_99
-
descending
-
_n_
- literal
- consists of 1 to 32,767 characters enclosed in single or
double quotation marks. Examples of literals include
Note: The surrounding quotation marks identify the
token as a literal, but SAS does not store these marks as part of the literal
token.
- number
- 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 folllowing forms as number tokens: scientific (E-) notation,
hexadecimal notation, missing value symbols, and date and time literals. Examples
of number tokens include
-
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. Examples of special-character tokens include
|
Placement and Spacing of Words in SAS Statements |
Spacing Requirements
- 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 in this book 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 may 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 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.