FILENAME Statement: Windows

Associates a SAS fileref with an external file or an output device, disassociates a fileref and external file, or lists attributes of external files.

Valid in: anywhere in a SAS program
Restriction: When SAS is in a locked-down state, the following FILENAME statement and access methods are not available. Your server administrator can re-enable this access method so that it is accessible in the locked-down state. For more information, see SAS Processing Restrictions for Servers in a Locked-Down State in SAS Language Reference: Concepts.
Windows specifics: Valid values for access-method; valid values for device-type; valid filenames for external-file; valid values for encoding; valid options in host-option-list
See: FILENAME Statement in SAS Statements: Reference

Syntax

System Description

This version is a simplified version of the FILENAME statement syntax. For the complete syntax and its explanation, see the FILENAME statement in FILENAME Statement in SAS Statements: Reference.

fileref

is any valid fileref, as discussed in “Using a Fileref” in the “Using External Files” section in SAS Companion for Windows.

The words AUX, CON, NUL, PRN, LPT1 - LPT9, and COM1 - COM9 are reserved words under Windows. Do not use them as filerefs.
For examples of using filerefs in member-name syntax (also called aggregate syntax), see Assigning a Fileref to a Directory . For a discussion of the rules SAS uses when accessing files through filerefs, see Understanding How Concatenated Directories Are Accessed. See Rules for User-Supplied SAS Names in SAS Language Reference: Concepts for length restrictions.

device-type

enables you to read and write data from devices rather than files. For information about the SFTP access method, see Configuring SSH Client Software in UNIX and Windows. The following values are valid:

CATALOG

reads a SAS catalog as an external flat file.

CLIPBOARD

reads text data from and writes text data to the clipboard on the host computer.

DATAURL

reads data from user-specified text by using the DATAURL access method.

DDE

reads data from and writes data to another application using Dynamic Data Exchange. For more information, see DDE Syntax within SAS.

DISK

reads data from and writes data to a disk file. Under Windows, DISK is the default for device-type.

DRIVEMAP

displays information about the available hard drives (local and networked).

DUMMY

specifies a null output device. This value is especially useful in testing situations.

EMAIL

lets you send electronic mail programmatically from SAS. For more information, see Sending Email Using SAS.

Restriction When SAS is in a locked-down state, the FILENAME statement, EMAIL access method is not available. Your server administrator can re-enable this access method so that it is accessible in the locked-down state. For more information, see SAS Processing Restrictions for Servers in a Locked-Down State in SAS Language Reference: Concepts.

FTP

lets you access information about other machines using TCP/IP. TCP/IP software and a WINSOCK.DLL must be installed on your local machine. You must also be able to connect to a machine that can function as an FTP server. For more information about using the FTP access method, see the FILENAME statement in SAS Statements: Reference.

Hadoop

accesses files on a Hadoop Distributed File System (HDFS) whose location is specified in a configuration file.

NAMEPIPE

writes data to a named pipe. For more information, see Using Named Pipes .

PIPE

writes data to an unnamed pipe. For more information, see Using Unnamed Pipes .

Requirement You must specify an external-file reference and the external-file reference must contain an absolute path and filename enclosed in quotation marks.

PLOTTER

indicates that you are accessing a plotter. Windows printing is not used. This device-type keyword is used solely in conjunction with SAS/GRAPH software.

PRINTER

indicates that you are accessing a printer file or device. By default, output is routed through Windows printing when you use this device-type keyword. For more information about altering your default printer, see SYSPRINT System Option: Windows.

SFTP

accesses remote files by using the SFTP protocol.

SOCKET

lets you read and write information over a TCP/IP socket. TCP/IP software and a WINSOCK.DLL must be installed on your local machine. The SOCKET access method uses the nonblocking method of issuing socket requests. For more information about using the SOCKET access method, see the FILENAME statement and FILENAME function in SAS Statements: Reference and SAS Functions and CALL Routines: Reference.

TEMP

creates a temporary file that exists only as long as the filename is assigned. The temporary file can be accessed only through the logical name and is available only while the logical name exists. A physical pathname is never shown to the user. If a physical pathname is specified, an error is returned. Files that are manipulated by the TEMP device can have the same attributes and behave identically to DISK files.

TERMINAL

useful only with output, causes output to be sent to the Message Log window.

For an example of specifying a device type in the FILENAME statement, see Advanced External I/O Techniques. The TAPE device-type keyword (documented in SAS Statements: Reference) is not applicable to the Windows operating environment. If you use the TAPE device-type keyword in your SAS program under Windows, you receive an error message. The DISK device-type keyword is accepted under Windows. However, it is ignored because disk files are the default under Windows.

URL

accesses remote files by using the URL access method.

WebDAV

accesses remote files by using the WebDAV protocol.

ZIP

accesses ZIP files.

directory

specifies the directory that contains the files that you want to access.

external-file

can be any valid Windows file specification that is enclosed in quotation marks. For more information, see Referencing External Files.

PERMISSION='permission-value'

specifies permissions to set for the specified fileref.

'permission-value'

A::<trustee_type>::<permissions>

A

Access permissions. No other values are supported.

trustee_type

u user
g group (all groups)
o other (all others, including the user who generates the file.)

The permission values take the values r (Read), w (Write), and x (Execute), in that order. If you do not want to grant one of these permissions, enter a - in its place (for example, r-x or rw-).

To specify more than one set of permission values, separate them with a comma within the quotation marks.
To specify Read and Execute permission for all groups that you are a member of, specify a permission value of A::g::r-x. To allow all users to have Read access to a file, specify a permission value of A::o::r--. For example, specify that option in the code as follows:
permission='A::o::r--'

ENCODING='encoding-value'

specifies the encoding to use when reading from or writing to the external file. The value for ENCODING= indicates that the external file has a different encoding from the current session encoding.

When you read data from an external file, SAS transcodes the data from the specified encoding to the session encoding. When you write data to an external file, SAS transcodes the data from the session encoding to the specified encoding.
For valid encoding values, see Encoding Values in SAS Language Elements in SAS National Language Support (NLS): Reference Guide.

host-option-list

names external I/O statement options that are specific to Windows. They can be any of the following:

ALTDEST=filename

is for use only with the PRINTER device type. Filename specifies a file destination to write to when you direct output to the fileref. Although the output is written to disk and not to the printer, the output is still formatted by using the printer driver that is associated with the printer that you specified with the external-file argument. For example,

filename groupHP printer
   "HP LaserJet 4si, 1st floor"
   altdest=
      "C:\My SAS Files\Printer output\out.prn";
uses the printer driver that is associated with the named printer (an HP LaserJet 4si) to create the output in out.prn. No output is actually sent to the printer when you use this fileref.

BLKSIZE=block-sizeBLK=block-size

specifies the number of bytes that are physically read or written in an I/O operation. The default is 8K. The maximum is 1M.

BLOCK | NOBLOCK

is used only in the context of named pipes. This option indicates whether the client is to wait if no data is currently available. BLOCK is the default value.

BYTE | MESSAGE

is used only in the context of named pipes. This option indicates the type of pipe. BYTE is the default value.

COMMAND

is used only in the context of Dynamic Data Exchange (DDE). This option enables you to issue a remote command for applications that do not use the SYSTEM topic name. For more information, see Referencing the DDE External File and Controlling Another Application Using DDE.

COMTIMEOUT=value

controls how a communications port time-out is handled. A time-out occurs when no data is available at the communications port for a period of time, usually 60 seconds. The COMTIMEOUT= option can have the following values:

EOF

returns an end-of-file (EOF) character when a time-out occurs. This behavior is the default. The EOF character causes the current DATA step to terminate.

WAIT

instructs the communications port to wait forever for data. This value overrides the time-out. In this case, no record is returned to the DATA step until data are available. This action can cause your program to go into an infinite loop, so use this value with caution.

ZERO

returns a record length of 0 bytes when a time-out occurs. However, the DATA step does not terminate; it simply tries to read data again.

CONSOLE=state

specifies the state of the DOS window when an application is opened using pipes. Valid states are:

MAX opens the DOS window maximized
MIN opens the DOS window minimized
NORMAL opens the DOS window using the default for the machine.
This host-option is valid only if you specify the PIPE keyword.

EOFCONNECT

is used only in the context of named pipes and is valid only when you are defining the server. This option indicates that if an end-of-file (EOF) character is received from a client, the server should try to connect to the next client.

HOTLINK

is used only in the context of Dynamic Data Exchange (DDE). For a complete description and an example of how to use this option, see Using the DDE HOTLINK.

IGNOREDOSEOF

is used in the context of I/O operations on variable record format files. When this option is specified, any occurrence of ^Z is interpreted as character data and not as an end-of-file marker.

LRECL=record-length

specifies the record length (in bytes). Under Windows, the default is 32767. The value of record-length can range from 1 to 1,073,741,823 ( 1 gigabyte).

Alternatively, you can specify a logical record length value by using the LRECL= System Option in SAS System Options: Reference

MOD

specifies that output should be appended to an existing file.

NOTAB

is used only in the context of Dynamic Data Exchange (DDE). This option enables you to use nontab character delimiters between variables. For more information about this option, see Using the NOTAB Option with DDE.

RECFM=record-format

controls the record format. The following values are valid under Windows:

F indicates fixed format.
N indicates binary format and causes the file to be treated as a byte stream. N is not valid for either the PIPE device type or the NAMEPIPE device type. If LRECL is not specified, the default value of 32767 bytes is used to read from or write to the file.
P indicates print format.
S370V indicates the variable S370 record format (V).
S370VB indicates the variable block S370 record format (VB).
S370VBS indicates the variable block with spanned records S370 record format (VBS).
V | D indicates variable format. This format is the default.
The S370 values are valid with z/OS types of files only. That is, files that are binary, have variable-length records, and are in EBCDIC format. If you want to use a fixed-format z/OS file, first copy it to a variable-length, binary z/OS file.

RETRY=seconds

is used only in the context of named pipes. This option specifies how long a named pipe client should wait for a busy pipe. The minimum (and default) value for seconds is 10.

SERVER | CLIENT

is used only in the context of named pipes. This option specifies the mode of a named pipe. The default value is SERVER.

TERMSTR=

specifies the end-of-line character for the file. Use this option to share files between the UNIX and Windows operating environments. Here are the valid values:

CRLF

Carriage return line feed. Use TERMSTR=CRLF to write files that are formatted for Windows. CRLF is the default.

LF

Line feed. Use TERMSTR=LF to write files that are formatted for UNIX.

NL

New line. Use TERMSTR=NL to write files that are formatted for UNIX.

Details

The FILENAME statement temporarily associates a valid SAS name with an external file or an output device. An external file is a file created and maintained in the Windows operating environment from which you need to read data.

Example: Referencing External Files

You can reference external files from a concatenated list of files or directories. The wildcard character * can be used in the FILENAME statement:
filename read ('c:\myfiles\*.*','c:\myotherfiles\abc.dat');
data new;
infile read;
input;
run;