Associates a SAS fileref with an external file or an output device;
disassociates a fileref and external file; lists attributes of external files
| Valid: |
anywhere
|
| Category: |
Data Access
|
FILENAME fileref
<device-type> 'external-file'
<host-options>;
|
FILENAME fileref <device-type>
<host-options>;
|
FILENAME fileref CLEAR | _ALL_
CLEAR;
|
FILENAME fileref LIST | _ALL_
LIST;
|
-
fileref
-
is any SAS name when you are assigning a
new fileref. When you are disassociating a currently-assigned fileref or when
you are listing file attributes with the FILENAME statement, specify a fileref
that was previously assigned with a FILENAME statement or a host-level command.
-
'external-file'
-
is the physical name of an external file.
The physical name is the name that is recognized by the operating environment.
Operating Environment Information:
For details on specifying the physical
names of external files, see the SAS documentation for your operating environment.
-
device-type
-
specifies the type of device. Values include
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. ![[cautend]](../common/images/cautend.gif)
-
CLEAR
-
disassociates one or more currently assigned
filerefs.
-
_ALL_
-
specifies that the CLEAR or LIST argument
applies to all currently-assigned filerefs.
-
LIST
-
writes the attributes of one or more files
to the SAS log.
Host-options specify details,
such as file attributes and processing attributes, that are specific to your
operating environment.
Operating Environment Information:
For
a list of valid specifications, see the SAS documentation for your operating
environment.
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.
-
external
file
-
is a file that is created and maintained
in the operating environment from which you need to read data, SAS programming
statements, or autocall macros or to which you want to write output. An external
file can be a single file or an aggregate storage location that contains many
individual external files.
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.
For an example, see
Associating a Fileref with an Aggregate Storage Location.
-
fileref
-
(a file reference name) is a shorthand reference
to an external file. Once you have associated a fileref with an external file,
you can use it as a shorthand reference for that file in SAS programming statements
(such as INFILE, FILE, and %INCLUDE) and in other commands and statements
in SAS software that access external files.
Use this form of the FILENAME statement to associate
a fileref with an external file on disk:
|
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:
|
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:
|
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.
|
FILENAME fileref LIST | _ALL_ LIST;
|
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.
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
;
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.