Chapter Contents |
Previous |
Next |
$VARYINGw. |
Valid: | in a DATA step |
Category: | Character |
Syntax | |
Syntax Description | |
Details | |
Examples | |
Example 1: Obtaining a Current Record Length Directly | |
Example 2: Obtaining a Record 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 an INPUT statement. |
Restriction: | Length-variable cannot be an array reference. |
Tip: | If length-variable is less than 1 or is missing, SAS reads no data from the corresponding record. This enables you to read both zero-length records and fields. If length-variable is greater than 0 but less than w, SAS reads the number of columns that are specified by length-variable. Then SAS pads the value with trailing blanks up to the maximum width that is assigned to the variable. If length-variable is greater than or equal to w, SAS reads w columns. |
Details |
Use $VARYINGw. when the length of a character value differs from record to record. After reading a data value with $VARYINGw., the pointer's position is set to the first column after the value.
Examples |
input fwidth 1. name $varying9. fwidth;
Data Lines* | Results |
---|---|
----+----1 |
|
5shark |
shark |
3sunfish |
sun |
8bluefish |
bluefish |
*Notice the result of reading the second data line. |
Use the LENGTH= option in the INFILE statement to obtain a record length indirectly. The input data lines and results follow the explanation of the SAS statements.
data one; infile file-specification length=reclen; input @; fwidth=reclen-9; input name $ 1-9 @10 class $varying20. fwidth; run;
The LENGTH= option in the INFILE statement assigns the internally stored record length to RECLEN when the first INPUT statement executes. The trailing @ holds the record for another INPUT statement. Next, the assignment statement calculates the value of the varying-length field by subtracting the fixed-length portion of the record from the total record length. The variable FWIDTH contains the length of the last field and becomes the length-variable argument to the $VARYING20. informat.
Data Lines | Results |
---|---|
----+----1----+----2 |
|
PATEL CHEMISTRY |
PATEL CHEMISTRY |
JOHNSON GEOLOGY |
JOHNSON GEOLOGY |
WILCOX ART |
WILCOX ART |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.