FILENAME Statement and Command

Associates a SAS fileref with an external file.
Valid in: client and server session
See: FILENAME Statement: Windows in SAS Companion for Windows, FILE Statement: UNIX in SAS Companion for UNIX Environments, and FILENAME Statement: z/OS in SAS Companion for z/OS.

Syntax

FILENAME 'filespec' <access-method> <operating-environment-options>

Optional Arguments

fileref
specifies the name of a file reference to an external file.
'filespec'
specifies the physical name of an external file so that the external file is recognized by the operating environment.
access-method
specifies a remote file access via a specific access method. For details, see the access methods that are supported in the FILENAME statement in SAS Statements: Reference.
operating-environment-options
specifies details, such as file attributes and processing attributes, that are specific to the operating environment.

Details

The FILENAME statement associates a SAS fileref (a file reference name) with a filespec. The fileref must conform to SAS naming rules. The form of the filespec varies according to operating environment. Some environments require a fully qualified filename; other environments might permit partial pathnames.
Filerefs are a shorthand method for specifying a file in SAS statements and commands. After you define a fileref, you can use the fileref in place of the longer file specification to reference the file throughout a SAS session or program.
A fileref remains associated with an external file only for the duration of the SAS session. The association is not permanent. Also, a fileref must be defined and the FILENAME statement must be executed before a SAS statement or command that uses the fileref can execute.

Using a FILENAME Statement for Script Files

A common use of the FILENAME statement is to define filerefs for SAS/CONNECT script files. A script's fileref can then be specified in SIGNON and SIGNOFF commands to identify the SAS/CONNECT script that starts or ends the connection.
You can define a default fileref for a script file in a FILENAME statement. The default script fileref is RLINK. If you specify RLINK as the fileref for your script, you do not need to specify a fileref or a filespec in SIGNON and SIGNOFF commands or statements. When SAS executes a SIGNON or a SIGNOFF command without a specified fileref or a filespec, SAS automatically searches for a file that is defined with RLINK as the fileref. If RLINK has been defined, SAS executes the corresponding script.

Using a FILENAME Statement in the SAS Autoexec File

You can insert a FILENAME statement in the SAS autoexec file to automatically start and end a SAS/CONNECT server session. An autoexec file contains SAS statements and commands that you set up to execute automatically each time you invoke SAS. Its purpose is to automate the execution of statements, commands, and entire programs that you use routinely in SAS processing. If you use an autoexec file that contains a FILENAME statement that defines your script's fileref, you do not have to type and execute the FILENAME statement each time you want to establish a connection.
For details about setting up an autoexec file, see the appropriate SAS Companion documentation for your environment and SAS Language Reference: Concepts.

Using a FILENAME Statement with the UPLOAD and DOWNLOAD Procedures

You can combine the FILENAME statement with the UPLOAD and DOWNLOAD procedures to copy external files between SAS sessions. For example, in the client session, use the FILENAME statement to assign a fileref. The fileref defines the target location for the external file copy. In the server session, use the FILENAME statement to assign a fileref to the file to be downloaded to the client session.

Examples

Example 1: Using a FILENAME Statement for a Script File

If a SAS/CONNECT script is written and copied to a directory in your client environment, you could use the FILENAME statement to define the default fileref RLINK for the script, as follows:
filename rlink 'external-file-name';
Because you defined RLINK as the script's fileref, you can use the shortest form of the SIGNON and SIGNOFF commands or statements. For example, to start the connection, enter the following:
signon;
If you use one script to start the connection and another script to end the connection, you must define a unique fileref for each script. For example:
filename rlink 'start-link-script-file';
filename endit 'end-link-script-file';
Subsequently, to start the connection, enter the following command or statement, which uses the default fileref RLINK for the sign-on script:
signon;
To end the connection, enter the following:
signoff endit;

Example 2: Using a FILENAME Statement with the UPLOAD and DOWNLOAD Procedures

Suppose you want to download an external file from a server session to a client session that runs in a directory-based operating environment. Submit the following FILENAME statement to assign the fileref in the client session:
filename lhost 'client-file-name';
Then remotely submit the following statements to assign the fileref in the server session and to perform the download:
rsubmit;
filename rhost 'server-file-name';
   proc download infile=rhost outfile=lhost;
   run;
endrsubmit;