Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
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 this 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 filepath and a filename. A filepath 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 using the FILENAME statement. You can identify a file in either way using the FILE and INFILE statements.

For example, you can refer to the input file where the class data are stored using a literal filepath, that is, a quoted string. The statement

   infile 'user.text.class';
opens the file USER.TEXT.CLASS for input. Similarly, if you want to output data to the file USER.TEXT.NEWCLASS, you need to reference the output file with the statement
   file 'user.text.newclass';

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

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

The following statements accomplish the same thing as the previous INFILE statement with the quoted filepath:

   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 described below:

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 filepath is specified, there is a limit of 64 characters to the operand.


Types of External Files

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.