Previous Page | Next Page

Functions and CALL Routines under UNIX

FILENAME Function: UNIX



Assigns or deassigns a fileref for an external file, directory, or output device.
Category: External Files
UNIX specifics: fileref can be assigned with an environment variable; valid values of device-type and host-options
See: FILENAME Function in SAS Language Reference: Dictionary

Syntax
Details

Syntax

FILENAME(fileref, filename <,device-type<,"host-options"<,dir-ref>>>)

fileref

specifies the fileref to assign to an external file. In a DATA step, fileref can be a character expression, a string enclosed in quotation marks, or a DATA step variable whose value contains the fileref. In a macro (for example, in the %SYSFUNC function), fileref is the name of a macro variable (without an ampersand) whose value contains the fileref to assign to the external file. (For information, see the FILENAME function in SAS Language Reference: Dictionary.)

Under UNIX, the fileref can be a UNIX environment variable. The fileref or the environment variable that you specify must be enclosed in double quotation marks.

filename

specifies the external file. Specifying a blank filename (" ") deassigns a fileref that was previously assigned.

Under UNIX, the filename differs according to the device type. See Device Information in the FILENAME Statement for information that is appropriate for each device. Remember that UNIX filenames are case sensitive.

In a DATA step, filename can be a character expression, a string enclosed in quotation marks, or a DATA step variable whose value contains the filename. In a macro, filename can be any expression.

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. It can be any one of the devices listed in Device Information in the FILENAME Statement. DISK is the default device type.

host-options

are options that are specific to UNIX. You can use any of the options that are available in the FILENAME statement. See FILENAME Statement: UNIX for a description of the host options.

Requirement: Enclose host options in quotation marks. If you have multiple host options, then all of the host options must be enclosed in one set of quotation marks. The following example shows the syntax:
rc=filename("try","MISCHL.FLAT.FILE1","ftp",
            'user="mischl1",host="sdcunx",prompt');
dir-ref

specifies the fileref that is assigned to the directory in which the external file resides.


Details

FILENAME returns a 0 if the operation is successful, and a nonzero number if it was not successful.

If you use the FTP access method to communicate with a remote system, SAS might return the following error message:

ERROR: Physical file does not exist.

This error is likely to occur when the fully qualified data set name is specified within single quotation marks. For example:

FILENAME fileref FTP 'system.dataset.name' USER='username'
                 PASS='password' HOST='ip_address';

By default, SAS appends the profile prefix to the beginning of the data set name. To prevent the profile prefix from being appended, enclose the data set name with both double and single quotation marks:

FILENAME fileref FTP "'external_file'" USER='username'
                 PASS='password' HOST='ip_address';

Previous Page | Next Page | Top of Page