用于读入长度不一的字符记录
| 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.
案例:
Example 1: Obtaining a Current Record Length Directly
- input fwidth 1. name $varying9. fwidth;
| Data Line | Results |
| ----+----1 | |
| 5shark | shark |
| 3sunfish | sun |
| 8bluefish | bluefish |
| * Notice the result of reading the second data line. | |
Example 2: Obtaining a Record Length Indirectly 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;
| Data Line | Results |
| ----+----1----+----2 | |
| PATEL CHEMISTRY | PATEL CHEMISTRY |
| JOHNSON GEOLOGY | JOHNSON GEOLOGY |
| WILCOX ART | WILCOX ART |
![]() |
![]() |
用法:
| $VARYINGw. length-variable |
Syntax Description
w 指定字符变量的最大宽度
specifies the maximum width of a character field for all the records in an input file.
| Default: | 8 if the length of the variable is undefined; otherwise, the length of the variable |
| Range: | 1-32767 |
length-variable 指定一个数值变量作为前面要读入的字符变量的宽度
specifies a numeric variable that contains the width of the character field in the current record. SAS obtains the value of length-variable by reading it directly from a field that is described in an INPUT statement or by calculating its value in the DATA step.
| Requirement: | You must specify length-variable immediately after $VARYINGw. in an INPUT statement. |
| Restriction: | Length-variable cannot be an array reference. |
| Tip: | If the value of length-variable is 0, negative, or missing, SAS reads no data from the corresponding record. A value of 0 for length-variable enables you to read 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. |
详细参考出处:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000193602.htm


雷达卡



京公网安备 11010802022788号







