Chapter Contents |
Previous |
Next |
LENGTH |
Valid: | in a DATA step |
Category: | Information |
Type: | Declarative |
Syntax | |
Arguments | |
Details | |
Comparisons | |
Examples | |
See Also |
Syntax |
LENGTH
variable-specification(s)
<DEFAULT=n>; |
Restriction: | Array references are not allowed. |
Tip: | 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. |
Default: | SAS assumes that the variables are numeric. |
Range: | 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. |
Default: | 8 |
Range: | 2 to 8 or 3 to 8, depending on your operating environment. |
Details |
In general, the length of a variable depends on
Operating Environment Information: Valid variable lengths depend on your operating environment. For details, see the SAS documentation for your operating environment.
Comparisons |
The ATTRIB statement can assign the length as well as other attributes of variables.
Examples |
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.
data testlength; informat FirstName LastName $15. n1 6.2; input firstname lastname n1 n2; length name $25 default=4; name=trim(lastname)||', '||firstname; datalines; Alexander Robinson 35 11 ; proc contents data=testlength; run; proc print data=testlength; run;
The following output shows a partial listing from PROC CONTENTS, as well as the report that PROC PRINT generates.
The SAS System 3 CONTENTS PROCEDURE -----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 |
See Also |
Statement:
| |||
For information on the use of the LENGTH statement in PROC steps, see SAS Procedures Guide |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.