![]() Chapter Contents |
![]() Previous |
![]() Next |
| $VARYINGw. |
| 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 |
| Default: | 8 if the length of the variable is undefined; otherwise, the length of the variable |
| Range: | 1-32767 |
| Requirement: | You must specify length-variable immediately after $VARYINGw. in a SAS statement. |
| Restriction: | Length-variable cannot be an array reference. |
| Tip: | If the value of length-variable is 1 or missing, SAS writes nothing to the output field. If the value of length-variable is greater than 0 but less than w, SAS writes the number of characters that are specified by length-variable. |
| 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.
| Values* | 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. | |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.