Assigning Filerefs to External Files or Devices with the FILENAME Statement

Introduction to the FILENAME Statement

The most common way to assign a fileref to an external file or device is with the FILENAME statement. There are several forms of the FILENAME statement, depending on the type of device you want to access. For more information, see "FILENAME Statement" on page 293.

Accessing DISK Files

The most common use of the FILENAME statement is to access DISK files. The FILENAME syntax for a DISK file is

  • FILENAME fileref <DISK> 'pathname' < options >;

The following FILENAME statement associates the fileref MyFile with the external file /users/mydir/myfile , which is stored on a disk device:

 filename myfile disk '/users/mydir/myfile'; 

The following FILENAME statement assigns a fileref of Prices to the file /users/pat/ cars . The FILE statement then refers to the file using the fileref:

 filename prices '/users/pat/cars';   data current.list;      file prices;      ...  PUT statements  ...   run; 

See "Concatenating Filenames in UNIX Environments" on page 138 for more information about using DISK files.

Debugging Code with DUMMY Devices

You can substitute the DUMMY device type for any of the other device types. This device type serves as a tool for debugging your SAS code without actually reading or writing to the device. After debugging is complete, replace the DUMMY device name with the proper device type, and your program will access the specified device type.

The FILENAME syntax for a DUMMY file is

  • FILENAME fileref DUMMY 'pathname' < options >;

Output to DUMMY devices is discarded.

Sending Output to PRINTER Devices

The PRINTER device type enables you to send output directly to a printer. The FILENAME syntax to direct a file to a PRINTER is

  • FILENAME fileref PRINTER '< printer >< printer-options >' < options >;

For example, this SAS program sends the output file to the BLDG3 printer:

 filename myfile printer 'bldg3';   data test;      file myfile;      put 'This will appear in bldg3 .';   run; 

See "Using PRTFILE and PRINT with a Fileref" on page 160 and "Using the PRINTTO Procedure in UNIX Environments" on page 161 for more information.

Using Temporary Files (TEMP Device Type)

The TEMP device type associates a fileref with a temporary file stored in the same directory as the Work data library. (See "Work Data Library" on page 120.) Using the TEMP device type enables you to create a file that lasts only as long as the SAS session.

The FILENAME syntax for a TEMP file is

  • FILENAME fileref TEMP < options >;

For example, this FILENAME statement associates Tmp1 with a temporary file:

 filename tmp1 temp; 

Accessing TERMINAL Devices Directly

To access a terminal directly, use the TERMINAL device type. The FILENAME syntax to associate a file with a terminal is

  • FILENAME fileref TERMINAL < 'terminal-pathname' >< options >;

The terminal-pathname must be a pathname of the special file associated with the terminal. Check with your system administrator for details. Enclose the name in quotation marks. If you omit the terminal pathname, the fileref is assigned to your terminal.

For example, this FILENAME statement associates the fileref Here with your terminal:

 filename here terminal; 

The following FILENAME statement associates the fileref ThatFile with another terminal:

 filename thatfile terminal '/dev/tty3'; 

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 SOCKET and FTP access methods . The forms of the FILENAME statement are

  • FILENAME fileref FTP 'external-file' < ftp-options >;

  • FILENAME fileref SOCKET 'external-file' < tcpip-options >;

  • FILENAME fileref SOCKET ':portno' SERVER < tcpip-options >;

These access methods are documented in SAS Language Reference: Dictionary . Under UNIX, the FTP access method supports an additional option:

MACH= 'machine'

  • identifies which entry in the . netrc file should be used to get the username and password. Consult the UNIX man page for more information about the .netrc file. You cannot specify the MACH option together with the HOST option in the FILENAME statement.

If you are transferring a file to UNIX from 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.


When you use the FTP access method to create a remote file, the UNIX permissions for that file are set to -rw-rw-rw- , which makes the file world-readable and world-writable. See the man page for chmod for information about changing file permissions.

SAS 9.1 Companion for UNIX Environments
SAS 9.1 Companion For Unix Enivronments
ISBN: 1590472101
EAN: 2147483647
Year: 2004
Pages: 185
Authors: SAS Institute © 2008-2017.
If you may any questions please contact us: