FGET Function


Copies data from the File Data Buffer (FDB) into a variable

Category: External Files

Syntax

FGET ( file-id , variable <, length >)

Arguments

file-id

  • specifies the identifier that was assigned when the file was opened, generally by the FOPEN function.

variable

  • in a DATA step, specifies a character variable to hold the data. In a macro, specifies a macro variable to hold the data. If variable is a macro variable and it does not exist, it is created.

length

  • specifies the number of characters to retrieve from the FDB. If length is specified, only the specified number of characters is retrieved (or the number of characters remaining in the buffer if that number is less than length). If length is omitted, 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: The 'FSEP Function' on page 562 for more information about delimiters.

Details

FGET returns 0 if the operation was successful, or -1 if the end of the FDB was reached or no more tokens were available.

After FGET is executed, the column pointer moves to the next read position in the FDB.

Examples

This example assigns the fileref MYFILE to an external file and attempts to open the file. If the file is opened successfully, it reads the first record into the File Data Buffer, retrieves the first token of the record and stores i t in the variable MYSTRING, and then closes the file. Note that in a macro statement you do not enclose character strings in quotation marks.

 %let filrf=myfile;  %let rc=%sysfunc(filename(filrf,  physical-filename  ));  %let fid=%sysfunc(fopen(&filrf));  %if &fid > 0 %then     %do;        %let rc=%sysfunc(fread(&fid));        %let rc=%sysfunc(fget(&fid,mystring));        %put &mystring;        %let rc=%sysfunc(fclose(&fid));     %end;  %let rc=%sysfunc(filename(filrf)); 

See Also

Functions:

  • 'FCLOSE Function' on page 519

  • 'FILENAME Function' on page 529

  • 'FOPEN Function' on page 550

  • 'FPOS Function' on page 556

  • 'FREAD Function' on page 558

  • 'FSEP Function' on page 562

  • 'MOPEN Function' on page 656




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net