Creating Variables |
Specifying Lengths for
Variables |
You can use a LENGTH
statement to specify a length (the number of bytes) for
Type before the first value is referenced elsewhere in the DATA
step. |
General form, LENGTH statement:
where
|
Examples:
length
Within your program, you include a LENGTH statement to assign a length to
accommodate the longest value of the variable data finance.newloan; set finance.records(drop=amount rate); length Type $ 8; TotalLoan+payment; if code='1' then Type='Fixed'; else Type='Variable'; run; |
Make sure the LENGTH statement appears before any other reference to the variable in the DATA step. The length of a new variable is determined by the first reference in the DATA step. If the variable has been created by an assignment statement, later use of the LENGTH statement will not alter its size. |
Now that you have added the LENGTH statement to your program,
the values of Type are no longer truncated. |
SAS Data Set Finance.Newloan
Account | Months | Payment | Code | TotalLoan | Type |
101-1092 | 60 | 467.43 | 1 | 467.43 | Fixed |
101-1731 | 360 | 958.57 | 2 | 1426.00 | Variable |
101-1289 | 36 | 325.02 | 2 | 1751.02 | Variable |
101-3144 | 12 | 308.52 | 1 | 2059.54 | Fixed |
103-1135 | 24 | 403.47 | 1 | 2463.02 | Fixed |
103-1994 | 60 | 393.07 | 2 | 2856.10 | Variable |
103-2335 | 48 | 128.02 | 1 | 2984.11 | Fixed |
103-3864 | 360 | 735.75 | 1 | 3719.86 | Fixed |
103-3891 | 360 | 257.75 | 2 | 3977.61 | Variable |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.