Specifies the number of bytes for storing variables.
||in a DATA step
under Windows UNIX
is a required argument and has the form
specifies one or more variables that are
to be assigned a length. This includes any variables in the DATA step, including
those dropped from the output data set.
are not allowed.
If the variable is character,
the length applies to the program data vector and the output data set. If
the variable is numeric, the length applies only to the output data set.
specifies that the preceding variables are
SAS assumes that the
variables are numeric.
specifies a numeric constant that is the
number of bytes used for storing variable values.
For numeric variables,
2 to 8 or 3 to 8, depending on your operating environment. For character variables,
1 to 32767 under all operating environments.
changes the default number of bytes that
SAS uses to store the values of any newly created numeric variables.
2 to 8 or 3 to 8, depending
on your operating environment.
- Avoid shortening numeric variables that contain
The precision of a numeric variable is closely
tied to its length, especially when the variable contains fractional values.
You can safely shorten variables that contain integers according to the rules
that are given in the SAS documentation for your operating environment, but
shortening variables that contain fractions might eliminate important precision.
In general, the length of a variable depends
whether the variable is numeric or character
how the variable was
whether a LENGTH or ATTRIB statement is present.
Subject to the rules for assigning lengths, lengths that
with the LENGTH statement can be changed in the ATTRIB statement and vice
versa. See SAS Variables in
SAS Language Reference: Concepts for information
about assigning lengths to variables.
Operating Environment Information: Valid variable
lengths depend on your operating environment. For details,
see the SAS documentation for your operating environment.
The ATTRIB statement can assign
the length as well as other attributes of variables.
This example uses a LENGTH statement to set the length
of the character variable NAME to 25. It also changes the default number of
bytes that SAS uses to store the values of newly created numeric variables
from 8 to 4. The TRIM function removes trailing blanks from LASTNAME before
it is concatenated with a comma (,) , a blank space, and the value of FIRSTNAME.
If you omit the LENGTH statement, SAS sets the length of NAME to 32.
informat FirstName LastName $15. n1 6.2;
input firstname lastname n1 n2;
length name $25 default=4;
Alexander Robinson 35 11
proc contents data=testlength;
proc print data=testlength;
The following output shows a partial listing from PROC
CONTENTS, as well as the report that PROC PRINT generates.
Setting the Length of a Variable
The SAS System 3
-----Alphabetic List of Variables and Attributes-----
# Variable Type Len Pos Informat
1 FirstName Char 15 8 $15.
2 LastName Char 15 23 $15.
3 n1 Num 4 0 6.2
4 n2 Num 4 4
5 name Char 25 38
The SAS System 4
OBS FirstName LastName n1 n2 name
1 Alexander Robinson 0.35000 11 Robinson, Alexander
information about the use of the LENGTH statement
in PROC steps, see
Base SAS Procedures Guide
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.