Previous Page | Next Page

File Access

Referring to an External File

Suppose that you have data for students in a class. You have recorded the values for the variables NAME, SEX, AGE, HEIGHT, and WEIGHT for each student and have stored the data in an external text file named USER.TEXT.CLASS. If you want to read these data into IML variables, you need to indicate where the data are stored. In other words, you need to name the input file. If you want to write data from matrices to a file, you also need to name an output file.

There are two ways to refer to an input or output file: a pathname and a filename. A pathname is the name of the file as it is known to the operating system. A filename is an indirect SAS reference to the file made by using the FILENAME statement. You can identify a file in either way by using the FILE and INFILE statements.

For example, you can refer to the input file where the class data are stored by using a literal pathname—that is, a quoted string. The following statement opens the file USER.TEXT.CLASS for input:

   infile 'user.text.class';

Similarly, if you want to output data to the file USER.TEXT.NEWCLASS, you need to reference the output file with the following statement:

   file 'user.text.newclass';

You can also refer to external files by using a filename. When using a filename as the operand, simply give the name. The name must be one already associated with a pathname by a previously issued FILENAME statement.

For example, suppose you want to reference the file with the class data by using a FILENAME statement. First, you must associate the pathname with an alias (called a fileref), such as INCLASS. Then you can refer to USER.TEXT.CLASS with the fileref INCLASS.

The following statements achieve the same result as the previous INFILE statement with the quoted pathname:

   filename inclass 'user.text.class';
   infile inclass;

You can use the same technique for output files. The following statements have the same effect as the previous FILE statement:

   filename outclass 'user.text.newclass';
   file outclass;

Three filenames have special meaning to IML: CARDS, LOG, and PRINT. These refer to the standard input and output streams for all SAS sessions, as follows:

CARDS

is a special filename for instream input data.

LOG

is a special filename for log output.

PRINT

is a special filename for standard print output.

When the pathname is specified, there is a limit of 64 characters to the operand.

Previous Page | Next Page | Top of Page