Chapter Contents

Previous

Next
FILENAME Statement

FILENAME Statement



Associates a SAS fileref with an external file.

Local and remote


Syntax
Syntax Description
With Script Files
Examples
In the SAS Autoexec File
With the DOWNLOAD and UPLOAD Procedures
Example

Syntax

FILENAME fileref 'filespec' <host-options>;

Syntax Description

fileref
specifies any SAS file reference name.

filespec
specifies the physical name of an external file. The physical name is specified so that the external file is recognized by the operating environment.

host-options
specify 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 (a host-dependent external filename). The fileref must conform to the rules for SAS names. The form of the filespec differs from system to system. On some systems you must include a fully-qualified filename. Other systems may 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. The FILENAME statement and filerefs are useful in many SAS programs, not just with SAS/CONNECT.

Note:   A fileref remains associated with an external file for the duration of the SAS session only. The association is not permanent. Also, a fileref must be defined before a SAS statement or command that uses the fileref can execute. Therefore, the FILENAME statement must execute before any statement or command that uses the fileref.  [cautionend]


With Script Files

A common use of the FILENAME statement in SAS/CONNECT is to define filerefs for script files.(footnote 1) A script's fileref can then be specified in SIGNON and SIGNOFF commands to identify the script that starts or terminates the link.

You can define a default fileref for a script 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; you simply use the command or the statement. When SAS executes a SIGNON or a SIGNOFF command without a 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.


Examples

Suppose your SAS Support Consultant writes a script and copies it to a directory on your local system. If you want to define the default fileref RLINK for your script, use the following FILENAME statement:

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 link, enter:

signon;

To terminate the link, enter:

signoff;

If you use one script to start the link and a different script to terminate the link, you must define a unique fileref for each script. For example, you can use the following FILENAME statements:

filename rlink 'start-link-script-file';
filename endit 'end-link-script-file';

Subsequently, to start the link, enter the following command or statement, which uses the default fileref RLINK for the sign-on script.

signon;

To terminate the link, enter:

signoff endit;


In the SAS Autoexec File

You can make starting and ending SAS/CONNECT even easier by adding the FILENAME statement that defines the script's fileref to an autoexec file. An autoexec file is a file of SAS statements and commands that you can set up to execute automatically each time you invoke the SAS System. 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 invoke the link.

Refer to the SAS Companion documentation for your environment and SAS Language Reference: Concepts for more information about setting up an autoexec file.


With the DOWNLOAD and UPLOAD Procedures

You can also use the FILENAME statement with the DOWNLOAD and UPLOAD procedures when copying external files. When you submit the FILENAME statement to define the fileref for the external file on the local host, you remote-submit the FILENAME statement to define the fileref for the external file on the remote host.


Example

Suppose you want to download an external file from the remote host to a directory-based local system. You submit the following FILENAME statement to assign the fileref on the local host:

filename lhost 'local-file-name';

Then remote-submit these statements to assign the fileref on the remote host and perform the download:

filename rhost 'remote-file-name';

   proc download infile=rhost outfile=lhost;
   run;

See Using Data Transfer Services for more examples of the FILENAME statement and the DOWNLOAD and UPLOAD procedures.


FOOTNOTE 1:  You can also use the FILENAME statement to specify an alternate 3270 keyboard translation table. [arrow]


Chapter Contents

Previous

Next

Top of Page

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