FOPEN Function


Opens an external file and returns a file identifier value

Category: External Files

See: FOPEN Function in the documentation for your operating environment.

Syntax

FOPEN ( fileref <, open -mode <, record-length <, record-format >>>)

Arguments

fileref

  • specifies the fileref assigned to the external file.

open-mode

  • specifies the type of access to the file:

    A

    APPEND mode allows writing new records after the current end of the file.

    I

    INPUT mode allows reading only (default).

    O

    OUTPUT mode defaults to the OPEN mode specified in the operating environment option in the FILENAME statement or function. If no operating environment option is specified, it allows writing new records at the beginning of the file.

    S

    Sequential input mode is used for pipes and other sequential devices such as hardware ports.

    U

    UPDATE mode allows both reading and writing.

  • Default: I

record-length

  • specifies the logical record length of the file. To use the existing record length for the file, specify a length of 0, or do not provide a value here.

record-format

  • specifies the record format of the file. To use the existing record format, do not specify a value here. Valid values are:

    B

    data are to be interpreted as binary data.

    D

    use default record format.

    E

    use editable record format.

    F

    file contains fixed length records.

    P

    file contains printer carriage control in operating environment-dependent record format. Note: For z/OS data sets with FBA or VBA record format, specify ˜P' for the record-format argument.

    V

    file contains variable length records.

Details

CAUTION:

  • Use OUTPUT mode with care. Opening an existing file for output overwrites the current contents of the file without warning.

The FOPEN function opens an external file for reading or updating and returns a file identifier value that is used to identify the open file to other functions. You must associate a fileref with the external file before calling the FOPEN function. FOPEN returns a 0 if the file could not be opened. You can assign filerefs by using the FILENAME statement or the FILENAME external file access function. Under some operating environments, you can also assign filerefs by using system comman ds.

Operating Environment Information: On some operating environments you must close the file at the end of the DATA step using the FCLOSE function. For details, see the SAS documentation for your operating environment.

Examples

Example 1: Opening a File Using Defaults

This example assigns the fileref MYFILE to an external file and attempts to open the file for input using all defaults. 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)); 

Example 2: Opening a File without Using Defaults

This example attempts to open a file for input without using defaults. Note that in a macro statement you do not enclose character strings in quotation marks.

 %let fid=%sysfunc(fopen(file2,o,132,e)); 

See Also

Functions:

  • 'DOPEN Function' on page 503

  • 'FCLOSE Function' on page 519

  • 'FILENAME Function' on page 529

  • 'FILEREF Function' on page 532

  • 'MOPEN Function' on page 656

Statement:

  • 'FILENAME Statement' on page 1169




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