Opens a file by directory ID and member name, and returns either the file identifier or a 0.
Category: | External Files |
See: | MOPEN Function: UNIX in SAS Companion for UNIX Environments |
MOPEN Function: z/OS in SAS Companion for z/OS |
is a numeric variable that specifies the identifier that was assigned when the directory was opened, generally by the DOPEN function.
is a character constant, variable, or expression that specifies the member name in the directory.
is a character constant, variable, or expression that 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 |
is a numeric variable, constant, or expression that 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.
is a character constant, variable, or expression that specifies a new record format for the file. To use the existing record format, do not specify a value here. The following values are valid:
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. |
%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));
'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.
%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));