Referencing an External File

To access an external file (such as a raw data file or a SAS program), you can
  1. submit a FILENAME statement to assign a fileref (file reference name or file shortcut) to the file
  2. use the fileref in subsequent SAS statements and commands that reference the file.

Filerefs perform the same function as librefs: temporarily pointing to a storage location for data. However, whereas librefs reference SAS data libraries, filerefs reference external files. FILENAME statements remain in effect until you change them, cancel them, or end your SAS session.


General form, FILENAME statement:
FILENAME fileref 'filename';

where

  • fileref is a valid SAS name you associate with an external file. The fileref must be 1 to 8 characters in length, begin with a letter (A-Z) or an underscore (_), and continue with any combination of numbers, letters, or underscores. You can also use the dollar sign ($), pound sign (#), and at sign (@) in filerefs.

  • filename is the fully qualified name or location of the file.


For example, this FILENAME statement temporarily associates the fileref Exercise with the external file C:\MyID\Therapy\Rawdata.dat in the Windows environment.
     filename exercise 'c:\myid\therapy\rawdata.dat';

You can check the filerefs in effect for your SAS session under File Shortcuts in the Explorer window.


Referencing Single Files and Aggregate Locations

You can use a FILENAME statement to associate a fileref with

  • an individual external file. In subsequent SAS statements and commands, you specify the fileref only.

  • an aggregate storage location, such as a directory, that contains a number of external files. To reference an external file with a fileref pointing to an aggregate storage location, you specify the fileref followed by the individual filename in parentheses:

If the file has . . . You . . . Example
the extension .sas can omit the extension when referencing the file. include tax(refund)
an extension other than .sas must include the extension and enclose the filename in quotes. include tax('net.dat')
no extension must enclose the filename in quotes. include tax('income')








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

Terms of Use & Legal Information | Privacy Statement