SAS Companion for the CMS Environment |
To access an external file,
specify its filename in a SAS statement or command. For example, this INCLUDE
command accesses a file that contains SAS statements and includes it into
the Program Editor window:
include 'mycode sas a'
These statements access an external file of data that
is used to create a SAS data set:
data mydata;
infile 'rawdata data b';
If you plan to use the same external file several times
in your SAS program, it is more efficient to use the FILENAME statement to
establish a fileref for the file. (See Advantages of Using the FILENAME Statement.) You can subsequently use the fileref
to refer to the file instead of specifying the filename again.
Note: Use the CMS FILEDEF command to assign a DDname, which is also
a logical name, only when you read OS/390 sequential or partitioned data sets
on OS/390 disks that are accessed by shared DASD, or when you read OS/390
simulated CMS files that are identified by filemode number 4.
|
Using the FILENAME Statement to Reference External Files |
A fileref
that is established by a FILENAME statement or FILENAME
function remains in effect until the SAS session ends, or until it is changed
or deleted by a FILENAME statement that specifies the same fileref. A FILENAME
statement for disk always overrides a CMS FILEDEF command for disk. When
you use a FILENAME statement to assign a fileref to a disk file, the native
CMS interface is used for I/O. If you use a CMS FILEDEF command to assign
a fileref to a disk file, OS/390 Simulation Services (provided by CMS) are
used.
- CAUTION:
- Do not assign different filerefs to the same physical
file or use the same fileref for concurrent access.
For example, if you assign a fileref to a file, then browse the file through
the FSLIST window, do not attempt to go to the Program Editor window and submit
a DATA step to write to the file while it is still displayed in the FSLIST
window.
There are several advantages to using the FILENAME statement
to identify external files.
- It is portable. The FILENAME statement is recognized
by SAS under all operating environments. You can develop a SAS program under
CMS and port it to another operating environment with fewer changes to your
program statements than if you used the CMS FILEDEF command.
- It is easier for novice CMS users to understand
than the CMS FILEDEF command.
- It enables you to list the filerefs that you have
assigned.
- It reduces processing time.
- Filerefs that are assigned by a FILENAME statement
are found before filerefs that are assigned that are by a FILEDEF command.
- Filerefs that are assigned by the FILENAME statement
use OS/390 Simulation only for nondisk files. Filerefs that are assigned by
a FILEDEF command always use OS/390 Simulation, even for disk files.
|
FILENAME Statement Syntax |
This section provides a brief overview of
FILENAME statement
syntax. For complete information about the FILENAME statement, see FILENAME. The general form
of the FILENAME statement is
FILENAME fileref | _ALL_ device-type
<'external-file'> <options>;
|
The FILENAME statement takes
the following options:
- fileref
- is a logical name by which the external
file is referenced. The fileref must begin with a letter or underscore and
must contain 1 to 8 characters consisting of letters, numbers, or underscores.
- _ALL_
- is a reserved fileref that is used only
to list or clear filerefs.
- device-type
- specifies the type of output or input device
for the file. If device-type not specified, SAS assumes that the file is on
disk.
- 'external-file'
- identifies the physical file to be associated
with the fileref.
- options
- is a list of options that control how the
file is read or written. Use a blank space to separate each option when you
specify more than one. All options use a keyword=value format.
FILENAME Statement Examples
- The following FILENAME statements associate the
fileref MYDATA with the external file HOUSES DATA A on disk. Note that the
second example is equivalent to the first, but the disk option is unnecessary.
filename mydata 'houses data a';
filename mydata disk 'houses data a';
- The following FILENAME statement associates the
fileref OUTDATA with the external file SOME FILE, in the FPOOL:USER3.DATA97
SFS directory.
filename outdata
'some file fpool:user3.data97';
- The following FILENAME statement associates the
fileref INDATA with the external file SURVEY MARCH on disk. If this fileref
is used for output, it is written to the first R/W disk. If this fileref is
used for input, the standard CMS minidisk search order is followed.
filename indata 'survey march';
- The following FILENAME statement associates the
fileref OUT with the virtual disk PUNCH. Any output to OUT is directed to
the virtual disk PUNCH.
filename out punch;
- The following FILENAME statement associates the
fileref MYLIB with the tape device defined as 182.
filename mylib tape 'tap2' ;
- The following FILENAME statement associates the fileref MYDIR
with the SFS directory FPOOL:MYUSER.MYDIR as an aggregate external file:
filename mydir 'fpool:myuser.mydir';
- The following FILENAME statement clears the association
between the fileref MYDATA and any device or file, provided that the fileref
was originally assigned by a FILENAME statement. CLEAR is assumed by default.
However, you may state it explicitly.
filename mydata clear;
- The following FILENAME statement concatenates
three files. When the fileref corresponding to a list of files to be concatenated
occurs in a later open-for-read operation, the data is read sequentially.
When the fileref occurs in a later open-for-write operation, output is written
to the first file in the list.
filename all
('mar file' 'apr file' 'may file');
- The following FILENAME statement specifies multiple
members in multiple MACLIBs. You cannot specify that output be sent to a MACLIB
file.
filename a
('one maclib' 'two maclib' 'three maclib');
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.