Using the FILENAME Statement or Function to Allocate External Files

Overview of Using the FILENAME Statement or Function to Allocate External Files

The FILENAME statement and FILENAME function associate a SAS fileref (file reference name) with the operating environment's name for an external file. This association is equivalent to allocating a physical file externally (using a JCL DD statement or a TSO ALLOCATE command) and assigning a fileref to it.
In interactive mode, if you issue a FILENAME statement or function or attempt to allocate a file with the FNAME window for a file that does not exist, and if you do not specify DISP=NEW, and if the file is not a UFS file, one of the following actions occurs:
  • If the SAS system option FILEPROMPT is in effect (the default), then a dialog box asks whether you want to create the external file. If you reply Yes, SAS creates the external file, using any attributes that you specified in the FILENAME statement. If you do not specify any attributes, SAS uses the values of the SAS system options FILEDEV=, FILEVOL=, FILEUNIT=, FILESPPRI=, and FILESPSEC=. For information about these options, see System Options in the z/OS Environment.
  • If the SAS system option NOFILEPROMPT is in effect, an error message indicating that the file could not be allocated is written to the SAS log.
For more information about the FILENAME function, see FILENAME Function: z/OS.

FILENAME Statement Syntax

This section provides only a brief overview of FILENAME statement syntax. For complete information about the FILENAME statement, see FILENAME Statement: z/OS.
The syntax of the FILENAME statement is
FILENAME fileref <device-type > 'physical-filename' <options . . . >;
fileref
identifies the external file. The fileref must conform to the rules for ddnames. That is, it can consist of one to eight letters, numbers, or the national characters $, @, and #. The first character must be either a letter or a national character, and an underscore (_) can appear in any position of the name. You can subsequently use the fileref to refer to this file in your SAS session or batch job. For more information, see Referring to External Files.
device-type
enables you to route output to an output device, disk, or tape file by specifying device type. If device-type is not defined for a new file, its value is taken from the SAS system option FILEDEV=.
'physical-filename' | ('physical-filename-1' . . . 'physical-filename-n') | 'physical-filename (*)' | 'physical-filename(beg*)' | 'physical-filename(*end)'
is the physical filename of the data set, enclosed in quotation marks (see Specifying Physical Files), or it can be a concatenation of physical filenames. For a concatenation, enclose each data set name in quotation marks, and enclose the entire group of file-specifications in parentheses. The maximum number of data sets in a concatenation is 200.
For a concatenation of members in a PDS, an asterisk (*) can be used in a wildcard file specification. The syntax 'physical-filename (*)' applies to all members of the PDS; (beg*) applies to all members or files whose names begin with beg, and (*end) applies to all files whose names end with end.
options
include standard options such as file disposition as well as options for SYSOUT data sets such as the destination for output and the number of copies desired. These options are described in detail in FILENAME Statement: z/OS. Generally, values for options can be specified either with or without quotation marks. However, values that contain special characters must be enclosed in quotation marks.

FILENAME Statement Examples

The following table provides examples of the FILENAME statement for z/OS:
FILENAME Statement Examples
Type of File
New or Existing File?
Example
sequential
existing
filename raw 'myid.raw.datax' disp=old;
new
filename x
'userid.newdata' disp=new
   space=(trk,(5,1)) unit=3380 volume=xyzabc
   recfm=fb lrecl=80 blksize=6160;
member of partitioned
existing
filename raw 'sas.raw.data(mem1)' disp=old;
new
filename dogcat 'userid.sas8.physn(optwrk)'
   disp=new space=(trk,(1,3,1))
   volume=xxx111 recfm=fb lrecl=255
   blksize=6120 dsorg=po;
partitioned extended
existing
filename mypdse 'sas.test.pdse' disp=old;
new
filename tpdse 'sas.test.pdse' dsntype=library
   space=(trk,(5,2,2)) lrecl=80    blksize=6160
   recfm=fb disp=(new,catlg) dsorg=po;
UFS: HFS files
existing
filename myhfs '/u/userid/myfile';
new
filename myhfs '/u/userid/myfile';
temporary
new
filename nextone '&mytemp' disp=new
   space=(trk,(3)) lrecl=80 blksize=6160;
tape
existing
filename mytape 'prod.data' vol=myvol  unit=tape
label=(1,SL);
new
filename tranfile 'sas.cport.file'
label=(1,SL)
   vol='042627' unit=cart blksize=8000
   disp=(new,keep);
concatenated
existing
filename concat12
   ('prod.payroll.data' 'prod.trans(may)');
wildcard
existing, in PDS
filename wild 'prod.payroll(d*)';
existing, in HFS
filename all '/u/userid/*.sas';
terminal
not applicable
filename term1  '*';
        or
filename term2 terminal;
printer
not applicable
filename prnt unit=printer sysout=a;
        or
filename prnt printer sysout=a;

Assigning Filerefs to Files on Other Systems (FTP and SOCKET Access Types)

You can access files on other systems in your network by using the FTP and SOCKET access methods. The forms of the FILENAME statement are:
FILENAME fileref FTP 'external-file' <ftp-options>;
FILENAME fileref SOCKET 'hostname:portno' <tcpip-options>;
FILENAME fileref SOCKET ':portno' SERVER <tcpip-options>;
These access methods are documented in the SAS Statements: Reference. On z/OS, the FTP access method supports an additional option:
MACH='machine'
identifies which entry in the .netrc file should be used to get the user name and password. You cannot specify the MACH option and the HOST option on the same FILENAME statement. The .netrc file resides on z/OS.
The SAS FTP access method accesses the .netrc file per the following search precedence:
  1. NETRC DD statement
  2. userid.NETRC
  3. UFS Home directory (~/.netrc)
The .netrc file contains the machine name, user ID, and password of various hosts that a user can FTP to, for example:
MACHINE hostname LOGIN userid PASSWORD xxxxxxx
If you are transferring a file to any UNIX or Windows file system from SAS in the z/OS operating environment and you want to use either the S370V or S370VB format to access that file, then the file must be of type RECFM=U and BLKSIZE=32760 before you transfer it.
Note:
  • The permissions of the .netrc file on UFS are not checked.
  • All characters of the .netrc keywords MACHINE, LOGIN, PASSWORD, and PASSWD must be uppercase or lowercase. Mixed case keywords are not supported.
  • Line numbers are not recommended in z/OS .netrc files, but they are supported.