Chapter Contents |
Previous |
Next |
FILENAME |
Valid: | anywhere |
Category: | Data Access |
Syntax |
FILENAME fileref
<device-type> 'external-file'
<host-options>; |
FILENAME fileref <device-type> <host-options>; |
FILENAME fileref CLEAR | _ALL_ CLEAR; |
FILENAME fileref LIST | _ALL_ LIST; |
Arguments |
Tip: | The association between a fileref and an external file lasts only for the duration of the SAS session or until you change it or discontinue it with another FILENAME statement. Change the fileref for a file as often as you want. |
Operating Environment Information: For details on specifying the physical names of external files, see the SAS documentation for your operating environment.
Tip: | Specify external-file when you assign a fileref to an external file. |
Tip: | You can associate a fileref with a single file or with an aggregate file storage location. |
DISK | specifies that the device is a disk
drive.
| ||||
DUMMY | specifies that the output to the
file is discarded.
| ||||
GTERM | indicates that the output device-type is a graphics device that will be receiving graphics data. | ||||
PIPE | specifies an unnamed pipe.
Note: Some operating
environments do not support pipes. | ||||
PLOTTER | specifies an unbuffered graphics output device. | ||||
PRINTER | specifies a printer or printer spool file. | ||||
TAPE | specifies a tape drive. | ||||
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.
| ||||
TERMINAL | specifies the user's terminal. |
Operating Environment Information: Additional specifications may be required when you specify some devices. See the SAS documentation for your operating environment before specifying a value other than DISK. Values in addition to the ones listed here may be available in some operating environments.
Tip: | Specify fileref to disassociate a single fileref. Specify _ALL_ to disassociate all currently assigned filerefs. |
Interaction: | Specify fileref to list the attributes of a single file. Specify _ALL_ to list the attributes of all files that have filerefs in your current session. |
Host Options |
Host-options
specify details, such as file attributes and processing attributes, that are
specific to your operating environment.
Operating Environment Information:
Details |
Operating Environment Information: Using the FILENAME statement requires host-specific information. See the SAS documentation for your operating environment before using this statement. Note also that host commands are available in some operating environments that associate a fileref with a file and that break that association.
For an example, see Associating a Fileref with an Aggregate Storage Location.
Operating Environment Information: Different operating environments call an aggregate grouping of files by different names, such as a directory, a MACLIB, or a partitioned data set. For details on specifying external files, see the SAS documentation for your operating environment.
Use this form of the FILENAME statement to associate a fileref with an external file on disk:
Syntax |
FILENAME fileref 'external-file' <host-options>; |
To associate a fileref to a file other than a disk file, you may need to specify a device type, depending on your operating environment, as shown in this form:
Syntax |
FILENAME fileref <device-type> <host-options>; |
The association between a fileref and an external file
lasts only for the duration of the SAS session or until you change it or discontinue
it with another FILENAME statement. Change the fileref for a file as often
as you want.
To associate a fileref with an output device, use this form:
Syntax |
FILENAME fileref device-type <host-options>; |
To disassociate a fileref from a file, use a FILENAME
statement, specifying the fileref and the CLEAR option.
Use a FILENAME statement to write the attributes of one or more external files to the SAS log. Specify fileref to list the attributes of one file; use _ALL_ to list the attributes of all files that have been assigned filerefs in your current SAS session.
Syntax |
FILENAME fileref LIST | _ALL_ LIST; |
Comparisons |
The FILENAME statement assigns a fileref to an external file. The LIBNAME statement assigns a libref to a SAS data set or to a DBMS file that can be accessed like a SAS data set.
Examples |
You can specify an external file either by associating a fileref with the file and then specifying the fileref or by specifying the physical file name in quotation marks:
filename sales 'your-input-file'; data jansales; /* specifying a fileref */ infile sales; input salesrep $20. +6 jansales febsales marsales; run; data jansales; /* physical filename in quotes */ infile 'your-input-file'; input salesrep $20. +6 jansales febsales marsales; run;
This example reads data from a file that has been associated with the fileref GREEN and creates a permanent SAS data set stored in a SAS data library that has been associated with the libref SAVE.
filename green 'your-input-file'; libname save 'SAS-data-library'; data save.vegetabl; infile green; input lettuce cabbage broccoli; run;
If you associate a fileref with an aggregate storage location, use the fileref, followed in parentheses by an individual filename, to read from or write to any of the individual external files stored there.
Operating Environment Information: Some operating environments allow you to read from but not write to members of aggregate storage locations. See the SAS documentation for your operating environment.
In this example each DATA step reads from an external file (REGION1and REGION2, respectively) that is stored in the same aggregate storage location and that is referenced by the fileref SALES.
filename sales 'aggregate-storage-location'; data total1; infile sales(region1); input machine $ jansales febsales marsales; totsale=jansales+febsales+marsales; run; data total2; infile sales(region2); input machine $ jansales febsales marsales; totsale=jansales+febsales+marsales; run;
In this example, the FILENAME statement associates the fileref OUT with a printer that is specified with a host-dependent option, and the FILE statement directs PUT statement output to that printer.
filename out printer host-options; data sales; file out print; input salesrep $20. +6 jansales febsales marsales; put _infile_; datalines; Jones, E. A. 124357 155321 167895 Lee, C. R. 111245 127564 143255 Desmond, R. T. 97631 101345 117865 ;
You can use the FILENAME and FILE statements to route PUT statement output to several different devices during the same session. To route PUT statement output to your display monitor, use the TERMINAL option in the FILENAME statement, as shown here:
filename show terminal; data sales; file show; input salesrep $20. +6 jansales febsales marsales; put _infile_; datalines; Jones, E. A. 124357 155321 167895 Lee, C. R. 111245 127564 143255 Desmond, R. T. 97631 101345 117865 ;
See Also |
Statements:
| |||||||||||||||
SAS
Windowing Interface Commands:
|
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.