LENGTH Statement


Specifies the number of bytes for storing variables

Valid: in a DATA step

Category: Information

Type: Declarative

See: LENGTH Statement in the documentation for your operating environment.

Syntax

LENGTH variable-specification(s) <DEFAULT= n >;

Arguments

variable-specification

  • is a required argument and has the form

    • variable(s) <$> length

    • where

  • variable

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

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

  • $

    • indicates that the preceding variables are character variables.

    • Default: SAS assumes that the variables are numeric.

  • length

    • specifies a numeric constant that is the number of bytes used for storing variable values.

    • 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= n

  • changes the default number of bytes that SAS uses to store the values of any newly created numeric variables.

  • Default: 8

  • Range: 2 to 8 or 3 to 8, depending on your operating environment.

CAUTION:

  • Avoid shortening numeric variables that contain fractions. 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 may eliminate important precision.

Details

In general, the length of a variable depends on

  • whether the variable is numeric or character

  • how the variable was created

  • whether a LENGTH or ATTRIB statement is present.

Subject to the rules for assigning lengths, lengths that are assigned with the LENGTH statement can be changed in the ATTRIB statement and vice versa. See SAS Variables in SAS Language Reference: Concepts for information on 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.

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 . n1 6.2;     input firstname lastname n1 n2;     length name  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.

Output 7.12
start example
 The SAS System                              3                   CONTENTS PROCEDURE  -----Alphabetic List of Variables and Attributes-----   #    Variable     Type    Len    Pos    Informat    ------------------------------------------------   1    FirstName    Char     15      8    .    2    LastName     Char     15     23    .    3    n1           Num       4      0    6.2    4    n2           Num       4      4    5    name         Char     25     38 
end example
 
 The SAS System                        4  OBS   FirstName   LastName      n1     n2          name   1    Alexander   Robinson   0.35000   11   Robinson, Alexander 

See Also

Statement:

  • ATTRIB Statement on page 1109

For information on the use of the LENGTH statement in PROC steps, see Base SAS Procedures Guide




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net