Reading Variable-Length Records |
Reading Variable-Length Fields |
The LENGTH= Option
Each record in the file referenced by the fileref Phonedat
contains a value for an employee ID number, name, and phone extension.
The first and third fields ( |
1---+----10---+----20 |
1802JOHNSON2123 |
1803BARKER2142 |
1804EDMUNDSON2325 |
1805RIVERS2543 |
1806MASON2646 |
1807JACKSON2049 |
1808LEVY2856 |
1809THOMAS2222 |
1810WARREN2003 |
1811VANDENBERGH2110 |
1812YEAGER2145 |
1813SMITH2025 |
1814HINES2243 |
1815TAYLOR2746 |
As you write the DATA step to read these values, remember
that you must accommodate the varying length of Name in each
individual record. |
data perm.phones; infile phondat . . .; |
But first, you need to determine the total length of each record. This is easily accomplished by using the LENGTH= option. |
General form, INFILE statement with LENGTH=
option:
where variable defines a numeric variable whose value is set to the length of the current record.
|
Here, the length of each record is assigned to the variable
reclen . As each record is read, the value of reclen
changes. |
data perm.phones; infile phondat length=reclen; input . . .; |
Raw Data File Phonedat
|
> |
reclen= 15 reclen= 14 reclen= 17 reclen= 14 reclen= 13 reclen= 15 reclen= 12 reclen= 14 |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.