| Formats |
| Valid: | in DATA step |
| Category: | Character |
| Alignment: | left |
| Syntax | |
| Syntax Description | |
| Details | |
| Examples | |
| Example 1: Obtaining a Variable Length Directly | |
| Example 2: Obtaining a Variable Length Indirectly | |
Syntax |
| $VARYINGw. length-variable |
specifies the maximum width of the output field for any output line or output file record.
| Default: | 8 if the length of the variable is undefined. Otherwise, the default is the length of the variable |
| Range: | 1-32767 |
specifies a numeric variable that contains the length of the current value of the character variable. SAS obtains the value of the length-variable by reading it directly from a field that is described in an INPUT statement, reading the value of a variable in an existing SAS data set, or calculating its value.
| Details |
Use $VARYINGw. when the length of a character value differs from record to record. After writing a data value with $VARYINGw., the pointer's position is the first column after the value.
| Examples |
An existing data set variable contains the length of a variable. The data values and the results follow the explanation of this SAS statement:
put @10 name $varying12. varlen;
NAME is a character variable of length 12 that contains values that vary from 1 to 12 characters in length. VARLEN is a numeric variable in the same data set that contains the actual length of NAME for the current observation.
| Value of name* | Results |
|---|---|
|
|
----+----1----+----2----+ |
New York 8 |
New York |
Toronto 7 |
Toronto |
Buenos Aires 12 |
Buenos Aires |
Tokyo 5 |
Tokyo |
| * The value of NAME appears before the value of VARLEN. | |
Use the LENGTH function to determine the length of a variable. The data values and the results follow the explanation of these SAS statements:
varlen=length(name); put @10 name $varying12. varlen;
The assignment statement determines the length of the varying-length variable. The variable VARLEN contains this length and becomes the length-variable argument to the $VARYING12. format.
| Values* | Results |
|---|---|
|
|
----+----1----+----2----+ |
New York |
New York |
Toronto |
Toronto |
Buenos Aires |
Buenos Aires |
Tokyo |
Tokyo |
| * The value of NAME appears before the value of VARLEN. | |
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.