Chapter Contents

Previous

Next
FILENAME

FILENAME



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


Syntax
Arguments
Host Options
Details
Host Information
Definitions
[1]Associating a Fileref with an External File
[2]Associating a Fileref with a Terminal, Printer, or Plotter
[3]Disassociating a Fileref from an External File
[4]Writing File Attributes to the SAS Log
Comparisons
Examples
Example 1: Specifying a Fileref or a Physical File Name
Example 2: Using a FILENAME and a LIBNAME Statement
Example 3: Associating a Fileref with an Aggregate Storage Location
Example 4: Routing PUT Statement Output
See Also

Syntax

[1]FILENAME fileref <device-type> 'external-file'
<host-options>;
[2]FILENAME fileref <device-type> <host-options>;
[3]FILENAME fileref CLEAR | _ALL_ CLEAR;
[4]FILENAME fileref LIST | _ALL_ LIST;


Arguments

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.
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.

'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.  [cautionend]
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.

device-type
specifies the type of device or the access method that is used if the fileref points to an input or output device or location that is not a physical file:
DISK specifies that the device is a disk drive.
Tip: When you assign a fileref to a file on disk, you are not required to specify DISK.
Alias: BASE
DUMMY specifies that the output to the file is discarded.
Tip: Specifying DUMMY can be useful for testing.
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.  [cautionend]

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.
Restriction: Do not specify a physical pathname. If you do, SAS returns an error.
Tip: Files manipulated by the TEMP device can have the same attributes and behave identically to DISK files.
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.  [cautionend]

CLEAR
disassociates one or more currently assigned filerefs.
Tip: Specify fileref to disassociate a single fileref. Specify _ALL_ to disassociate all 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.
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:   For a list of valid specifications, see the SAS documentation for your operating environment.  [cautionend]


Details

Host Information

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.   [cautionend]


Definitions

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.

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.  [cautionend]

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.


[1]Associating a Fileref with an External File

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.

[2]Associating a Fileref with a Terminal, Printer, or Plotter

To associate a fileref with an output device, use this form:


Syntax

FILENAME fileref device-type <host-options>;

[3]Disassociating a Fileref from an External File

To disassociate a fileref from a file, use a FILENAME statement, specifying the fileref and the CLEAR option.

[4]Writing File Attributes to the SAS Log

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


Example 1: Specifying a Fileref or a Physical File Name

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;

Example 2: Using a FILENAME and a LIBNAME Statement

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;

Example 3: Associating a Fileref with an Aggregate Storage Location

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.  [cautionend]

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;

Example 4: Routing PUT Statement Output

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:
FILE
%INCLUDE
INFILE
FILENAME, CATALOG Access Method
FILENAME, FTP Access Method
FILENAME, SOCKET Access Method
LIBNAME
SAS Windowing Interface Commands:

FILE and INCLUDE


Chapter Contents

Previous

Next

Top of Page

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