Previous PageNext Page

The LENGTH statement
The LENGTH statement is used to define the length of variables. Other statements like the INPUT statement can also define the length of variables. Characteristics (like length) of variables are defined the first time the compiler encounters them. That is:
Data New;
Input X
Y 1-3
A $
B $1.;
Defines X and Y as numeric variables with the default length (8 bytes), A as a character variable with the default length (8 bytes), and B as a character variable one byte long.
But the following code:
Data New;
Length X 8 Y 2 A $1 B $20;
Input X
Y 1-3
A $
B $1.;
Defines X as numeric variables with length 8 bytes, Y as numeric variables with length 2 bytes, A as a character variable of length one, and B as a character variable twenty bytes long.
Two notes:
Use the LENGTH statement before the INPUT statement. Why?

The LENGTH statement is not the FORMAT statement.
Length X 8. Y 2. A $1. B $20.;
The above is legal, and has the same effect as the LENGTH statement in the data step above.

Previous PageTable Of ContentsNext Page