Chapter Contents

Previous

Next
SAS Companion for the CMS Environment

Accessing an External File

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.  [cautionend]


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.  [cautionend]


Advantages of Using the FILENAME Statement

There are several advantages to using the FILENAME statement to identify external 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


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.