Previous Page | Next Page

Language Reference

FILE Statement

FILE filename <RECFM=N> <LRECL=operand> ;

The FILE statement opens an external file for output.

The arguments to the FILE statement are as follows:

filename

is a name (for defined filenames), a quoted literal, or an expression in parentheses (for pathnames).

RECFM=N

specifies that the file be written as a pure binary file without record-separator characters.

LRECL=operand

specifies the record length of the output file. The default record length is 512.

You can use the FILE statement to open a file for output, or if the file is already open, to make it the current output file so that subsequent PUT statements write to it. The FILE statement is similar in syntax and operation to the INFILE statement. The FILE statement is described in detail in Chapter 8.

The filename argument is either a predefined filename or a quoted string or character expression in parentheses referring to the pathname. You can refer to an input or output file two ways: by a pathname or by a filename. The pathname is the name as known to the operating system. The filename is a SAS reference to the file established directly through a connection made with the FILENAME statement. You can specify a file in either way in the FILE and INFILE statements. To specify a filename as the operand, just give the name. The name must be one already connected to a pathname by a previously issued FILENAME statement. However, two special filenames are recognized by the SAS/IML language: LOG and PRINT. These refer to the standard output streams for all SAS sessions. To specify a pathname, enclose it in quotes or specify an expression in parentheses that yields the pathname.

When the pathname is specified, the operand is limited to 64 characters.

Note that RECFM=U is equivalent to RECFM=N. If an output file is subsequently read by a SAS DATA step, RECFM=N must be specified in the DATA step to guarantee that the file is read properly.

Following are several valid uses of FILE statement:

file "student.dat";           /* by literal pathname   */

filename out "student.dat";   /* specify filename OUT  */
file out;                     /* refer to by filename  */

file print;                   /* standard print output */
file log;                     /* output to log         */

file "student.dat" recfm=n;   /* for a binary file     */
Previous Page | Next Page | Top of Page