Previous Page | Next Page

SAS Statements under Windows

FILENAME Statement: Windows



Associates a SAS fileref with an external file or a logical file device.
Valid in: anywhere in a SAS program
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 Language Reference: Dictionary

Syntax
Details
Example
Referencing External Files
See Also

Syntax

FILENAME fileref <device-type> 'external-file' <ENCODING='encoding-value'><host-option-list>;
FILENAME fileref device-type <'external-file'> <ENCODING=encoding-value><host-option-list>;
FILENAME fileref <device-type> ('directory-1'<,...directory-n'>) <ENCODING=encoding-value><host-option-list>;

Note:   This version is a simplified version of the FILENAME statement syntax. For the complete syntax and its explanation, see the FILENAME statement in SAS Language Reference: Dictionary.  [cautionend]

fileref

is any valid fileref, as discussed in Using a Fileref.

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.

Note:   The words AUX, CON, NUL, PRN, LPT1 - LPT9, and COM1 - COM9 are reserved words under Windows. Do not use them as filerefs.  [cautionend]

device-type

enables you to read and write data from devices rather than files. The following values are valid:

CATALOG

reads a SAS catalog as an external flat file.

COMMPORT

reads data from and writes data to a communications port.

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 E-Mail Using SAS.

FTP

lets you access information on other machines using TCP/IP. You must have TCP/IP software and a WINSOCK.DLL 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 Language Reference: Dictionary.

NAMEPIPE

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

NOTESDB

writes data to a Lotus Notes database. For more information, see Populating a Lotus Notes Database Using the DATA Step and SCL Code.

PIPE

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

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 the system option SYSPRINT System Option: Windows.

SOCKET

lets you read and write information over a TCP/IP socket. You must have TCP/IP software and a WINSOCK.DLL 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 Language Reference: Dictionary.

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

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

For an example of specifying a device type in the FILENAME statement, see Advanced External I/O Techniques.

Note:   The TAPE device-type keyword (documented in SAS Language Reference: Dictionary) is not applicable to the Windows operating environment. If you use the TAPE device-type keyword in your SAS program under Windows, you will receive an error message. Also, while the DISK device-type keyword is accepted under Windows, it is ignored because disk files are the default under Windows.  [cautionend]

external-file

can be any valid Windows file specification that is enclosed in quotes. (for more information, see Referencing External Files).

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.
BAUD=

sets the baud rate. The value for baud-rate depends on your communications hardware. It must be an integer. This host option is valid only if you specify the COMMPORT device-type keyword.

BITS=

sets the transmission bits. Values are 5 through 8. This host option is valid only when you specify the COMMPORT device-type keyword.

Note:   For the 8250 serial port, invalid combinations are 5 data bits with 2 stop bits and 6, 7, or 8 data bits with 1.5 stop bits.  [cautionend]

BLKSIZE=block-size
BLK=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 timeout is handled. A timeout 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 timeout 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 timeout. 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 timeout occurs. However, the DATA step does not terminate; it simply tries to read data again.

This host-option is valid only if you specify the COMMPORT device-type keyword.

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.
DROPNULL=

is used to discard null bytes when they are received. The valid values are

ON

specifies to discard null bytes when they are received.

OFF

specifies not to discard null bytes when they are received. OFF is the default value.

This host option is valid only if you specify the COMMPORT device-type keyword. For example:

filename portin commport 'com1:' dropnull=off;
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.

FLOW=

controls the transmission control flow. Values are: XONXOFF, DTRDSR, or RTSCTS. This host option is valid only if you specify the COMMPORT device-type keyword.

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 256. 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.

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.

PARITY=

sets the parity check bit. Values are NONE, ODD, EVEN, MARK, or SPACE. This host option is valid only if you specify the COMMPORT device-type keyword.

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 the PIPE or the NAMEPIPE device types. If LRECL is not specified, by default SAS reads 256 bytes at a time from 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.

RCONST=seconds

specifies the initial read time-out value in 0.001 of a second (1000 = 1 second). The default is 8 seconds. This host-option is valid only if you specify the COMMPORT device-type keyword.

RMULTI= seconds

specifies the subsequent read time-out value in 0.001 of a second (1000 = 1 second). This host-option is valid only if you specify the COMMPORT device-type keyword.

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.

STOP=

sets the stop bit. Values are ONE, TWO, ONEHALF. This host option is valid only if you specify the COMMPORT device-type keyword.

Note:   For the 8250 serial port, invalid combinations are 5 data bits with 2 stop bits and 6, 7, or 8 data bits with 1.5 stop bits.  [cautionend]

WCONST=seconds

specifies the initial time-out value in 0.001 of a second (1000 = 1 second). This host option is valid only if you specify the COMMPORT device-type keyword.

WMULTI=seconds

specifies the subsequent time-out value in 0.001 of a second (1000 = 1 second). This host option is valid only if you specify the COMMPORT device-type keyword.


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


Example 1: 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;


See Also

Previous Page | Next Page | Top of Page