Reading Variable-Length Records |
Lesson
Summary |
This page contains |
I. Text Summary
To go to the page where a task, programming feature, or concept was presented, select a link. |
Record Formats A record format specifies the characteristics of the organization of records in a file. Some operating systems have two types of record formats:
External files that have fixed-length records have an end-of-record marker after a predetermined number of columns. A typical record length is 80 columns. External files that have variable-length records have an end-of-record marker after the last field. When records contain fields of varying widths or a varying number of fields, variable-length records can use space more efficiently. |
Variable-Length Records That Have a Varying Field
Width The length of a record may vary because the length of a specific field varies from record to record. To read a file that has a variable-length field, a DATA step should include statements to
|
Variable-Length Records That Have a Varying Number
of Fields Records in an external file may contain a varying number of fields. The first three lines of the DATA step that are used to read a file that contains a varying number of fields are similar to those that are used to read a file that contains a variable-length field. You need to
|
The LENGTH= Option A LENGTH= option in the INFILE statement creates a numeric variable whose value is the length of the current record. Although the LENGTH= option is specified in the INFILE statement, the variable is not assigned a value until an INPUT statement is executed, and the SAS System determines the length of the record that is being read. |
The $VARYINGw. Informat The $VARYINGw. informat is a special SAS informat that enables you to read a character value that has a different length from record to record. Before you can specify the $VARYINGw. informat, you must define the value of the length-variable. |
II. Syntax
To go to the page where a statement or option was presented, select a link. Variable-Length Records That Have a Varying Field Width |
LIBNAME libref 'SAS-data-library'; |
FILENAME fileref 'filename'; |
DATA SAS-data-set; |
INFILE raw-data-file LENGTH=total-length-variable; |
INPUT variable @; |
variable-length-variable=total-length-variable - value; |
|
RUN; |
Variable-Length Records That Have a Varying Number of Fields |
LIBNAME libref 'SAS-data-library'; |
FILENAME fileref 'filename'; |
DATA SAS-data-set; |
INPUT variable @; |
DO index-variable specification; |
INPUT variable(s) @; |
OUTPUT; |
END; |
RUN; |
|
III. Sample Programs
Variable-Length Records That Have a Varying Field Width libname perm 'c:\records\phone'; filename phonedat 'c:\records\phone\new.dat'; data perm.phones; infile phonedat length=reclen; input ID 4. @; namelen=reclen-8; input Name $varying10. namelen PhoneExt; run;
libname perm 'c:\records\patient'; filename bpdat 'c:\records\patient\bp.dat'; data perm.health; infile bpdata length=reclen; input ID 4. @; do index=6 to reclen by 15; input Date : date7. BP $ @; output; end; run; |
IV. Points to Remember
|
|
Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.