Chapter Contents |
Previous |
Next |
SAS Component Language: Reference |
In order to read record values from the external file, your SCL program must first copy a record from the file into the FDB. Then it must copy the contents of the FDB into the SDV to make the values available to your SCL program. A value can be either part of a record or an entire record. Unless you must read values separately for some reason, reading an entire record as a single value is the easier technique to use. To complete the process of reading values from an open file, follow these steps:
Order of Reading Records |
Many types of external files can be read only sequentially, from the first record to the last. However, when a file supports random access, you can use SCL functions to change that sequence and either reread a particular record or start at the first record and reread the entire file. For more information, see Changing the Sequence of Reading Records.
Reading Record Values into the SDV |
length=finfo(fileid,'lrecl'); reclen=inputn(length,'best.'); rc=fget(fileid,row,reclen);If ROW is a nonwindow variable instead of a window variable, then values that are read from the FDB are in the SDV, but they are not displayed in the window until they are assigned to a window variable.
Note: The code in the preceding example is
host specific. See the SAS documentation for your operating environment for
more information.
You determine whether the contents are treated as one value or as a series of values. There is a column pointer in the FDB that is set to 1 when the contents are read. By default, the FGET function copies the value from the current position of the column pointer to the next separator character. The default separator character is one blank. Therefore, the default action of the FGET function is to copy the value from the current position of the column pointer to the next blank. (To designate a different character as the separator character, use the FSEP function).
After each FGET function, the column pointer is positioned one column past the last character that was read. When the FDB contains no more values, the FGET function returns -1 to signal that it has reached the end of the FDB.
Reading Records as Separate Values |
When you read the FDB contents as separate values, you can locate these values by positioning the FDB column pointer at the column where the value begins or by specifying the character that separates these values. By default, the separator character for file records is a blank.
Identifying a Value's Starting Column |
The following example shows how to read separate values when you know the numbers of the columns where the values start. This example reads record values into the variables NAME, HEIGHT, and WEIGHT by using the FPOS function to specify the position of the "read" pointer.
rc=fget(fileid,name,20); rc=fpos(fileid,21); rc=fget(fileid,height); rc=fpos(fileid,28); rc=fget(fileid,weight);
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.