Chapter Contents

Previous

Next
LENGTH

LENGTH



Declares variables and specifies their length and whether their data type is numeric or character

Category: Declarative Statement
Comparisons: SAS Statement with limitations in SCL


Syntax
Details
Example
See Also

Syntax

LENGTH<variable-list><DEFAULT=n>;

variable-list
is one or more variables, specified as variable-1 <. . . variable-n> <$> length, where

variable
names a variable to be assigned a length.

$
designates that the preceding variable or variables are character type.

length
is the length of the preceding variable or variables. Length can range from 1 to 32,767 for character variables. All numeric variables have a length of 8. If you specify a different length for a numeric variable, SCL still reserves 8 bytes for it.

Type: Character

DEFAULT=n
is the maximum length of character variables that are not defined by a LENGTH statement. If this option is not used, the default length for character variables is 200.

Type: Numeric


Details

In SCL, LENGTH is a declarative statement and can be used only to set the lengths of nonwindow variables. If you attempt to specify a length for a window variable, a compile error occurs.

You typically place LENGTH statements at the beginning of a program, before the first labeled section. A compiler error occurs if you attempt to place a LENGTH statement within a DO group or within a conditional clause.

You can use the LENGTH statement to reduce the amount of memory required for storing character-type nonwindow variables. For example, if your program assigns only single-character values to the variable CODE, and if the default length of character variables is 200, then you can save 199 bytes of storage space by defining the length of the variable explicitly in the SCL program. To do so, use a statement like the following:

length code $ 1;

For details about the LENGTH statement in the base SAS language, see SAS Language Reference: Dictionary .


Example

Set the maximum length of all character variables that are not defined by a LENGTH statement to 150:

length default=150;
length a $ 8;
INIT:
   b='';
   max_a=mlength(a);
   max_b=mlength(b);
   put max_a= max_b=;
return;
The output is:
max_a=8 max_b=150

See Also

DECLARE


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.