MOPEN Function


MOPEN Function

Opens a file by directory id and member name , and returns the file identifier or a 0

Category: External Files

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

Syntax

MOPEN ( directory-id , member-name < open -mode <, record-length <, record-format >>>)

Arguments

directory-id

  • specifies the identifier that was assigned when the directory was opened, generally by the DOPEN function.

member-name

  • specifies the member name in the directory.

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.

    W

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

  • Default: I

record-length

  • specifies a new logical record length for 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 a new record format for the file. To use the existing record format, do not specify a value here. Valid values are:

    B

    specifies that data is to be interpreted as binary data.

    D

    specifies the default record format.

    E

    specifies the record format that you can edit.

    F

    specifies that the file contains fixed-length records.

    P

    specifies that the file contains printer carriage control in operating environment-dependent record format.

    V

    specifies that the file contains variable-length records.

Details

MOPEN returns the identifier for the file, or 0 if the file could not be opened. You can use a file-id that is returned by the MOPEN function as you would use a file-id returned by the FOPEN function.

CAUTION:

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

The member is identified by directory-id and member-name instead of by a fileref. You can also open a directory member by using FILENAME to assign a fileref to the member, followed by a call to FOPEN. However, when you use MOPEN, you do not have to use a separate fileref for each member.

If the file already exists, the output and update modes default to the operating environment option (append or replace) specified with the FILENAME statement or function. For example,

 %let rc=%sysfunc(filename(file,  physical-name  ,,mod));  %let did=%sysfunc(dopen(&file));  %let fid=%sysfunc(mopen(&did,  member-name  ,o,0,d));  %let rc=%sysfunc(fput(&fid,This is a test.));  %let rc=%sysfunc(fwrite(&fid));  %let rc=%sysfunc(fclose(&fid)); 

If 'file' already exists, FWRITE appends the new record instead of writing it at the beginning of the file. However, if no operating environment option is specified with the FILENAME function, the output mode implies that the record be replaced .

If the open fails, use SYSMSG to retrieve the message text.

Operating Environment Information: The term directory in this description refers to an aggregate grouping of files that are managed by the operating environment. Different host operating environments identify such groupings with different names , such as directory, subdirectory, MACLIB, or partitioned data set. For details, see the SAS documentation for your operating environment.

Opening a directory member for output or append is not possible in some operating environments.

Examples

This example assigns the fileref MYDIR to a directory. Then it opens the directory, determines the number of members , retrieves the name of the first member, and opens that member. The last three arguments to MOPEN are the defaults. Note that in a macro statement you do not enclose character strings in quotation marks.

 %let filrf=mydir;  %let rc=%sysfunc(filename(filrf,  physical-name  ));  %let did=%sysfunc(dopen(&filrf));  %let frstname=' ';  %let memcount=%sysfunc(dnum(&did));  %if (&memcount > 0) %then     %do;        %let frstname =           %sysfunc(dread(&did,1));        %let fid =           %sysfunc(mopen(&did,&frstname,i,0,d));  macro statements to process the member  %let rc=%sysfunc(fclose(&fid));     %end;  %else     %put %sysfunc(sysmsg());  %let rc=%sysfunc(dclose(&did)); 

See Also

Functions:

  • 'DCLOSE Function' on page 484

  • 'DNUM Function' on page 502

  • 'DOPEN Function' on page 503

  • 'DREAD Function' on page 507

  • 'FCLOSE Function' on page 519

  • 'FILENAME Function' on page 529

  • 'FOPEN Function' on page 550

  • 'FPUT Function' on page 557

  • 'FWRITE Function' on page 564

  • 'SYSMSG Function' on page 847




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