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

  • 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

  • numbers

  • literals

  • special characters.

Types of Words or Tokens

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 Table 3.1 on page 19. Here are some examples of name tokens:

    • data

    • _new

    • yearcutoff

    • year_99

    • descending

    • _n_

    Table 3.1: Maximum Length of User-Supplied SAS Names

    SAS Language Element

    Maximum Length

    Arrays

    32

    CALL routines

    16

    Catalog entries

    32

    DATA step statement labels

    32

    DATA step variable labels

    256

    DATA step variables

    32

    DATA step windows

    32

    Engines

    8

    Filerefs

    8

    Formats, character

    31

    Formats, numeric

    32

    Functions

    16

    Generation data sets

    28

    Informats, character

    30

    Informats, numeric

    31

    Librefs

    8

    Macro variables

    32

    Macro windows

    32

    Macros

    32

    Members of SAS data libraries (SAS data sets, views, catalogs, indexes) except for generation data sets

    32

    Passwords

    8

    Procedure names (first 8 characters must be unique, and may not begin with 'SAS')

    16

    SCL variables

    32

literal

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

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 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' on page 17.

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.

Examples

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




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