Previous Page | Next Page

SAS Component Language Dictionary

FGET



Copies data from the File Data Buffer (FDB)
Category: External File

Syntax
Details
Example
See Also

Syntax

sysrc=FGET(file-id,cval<,length>);

rc

contains the return code for the operation:

0

successful

-1

the end of the FDB was reached, or no more tokens were available.

Type: Numeric

file-id

is the identifier that was assigned when the file was opened. If file-id is invalid, the program halts.

Type: Numeric

cval

is a character variable to hold the data.

Note:   This parameter is an update parameter. See Input, Output, and Update Parameters for more information.  [cautionend]

Type: Character

length

specifies how many characters to retrieve from the FDB.

Type: Numeric


Details

FGET copies data from the FDB into a character variable. If length is specified, then only the specified number of characters is retrieved (or the number of characters remaining in the buffer, if that number is less). If length is omitted, then all characters in the FDB from the current column position to the next delimiter are returned. The default delimiter is a blank. The delimiter is not retrieved. (See FSEP for more information about delimiters.)

After FGET is executed, the column pointer is automatically moved to the next "read" position in the FDB.


Example

Read the first record in the file specified by the user and copy the first token into the variable THESTRING.

   /* Assign the fileref THEFILE to the physical */
   /* filename that is stored in the    */
   /* variable FNAME and open it in append mode.  */
rc=filename( 'thefile',fname);
fileid=fopen('thefile');
if (fileid>0) then
   do;
         /* Read the first record, retrieve the  */
         /* first token of the record and store  */
         /* it in the variable THESTRING.        */
      rc=fread(fileid);
      rc=fget(fileid,thestring);
      put thestring;
      rc=fclose(fileid);
   end;
rc=filename('thefile','');


See Also

FPOS

FREAD

FSEP

Previous Page | Next Page | Top of Page