FILEEXIST Function

Verifies the existence of an external file by its physical name.

Category: External Files
See: FILEEXIST Function: Windows in SAS Companion for Windows
FILEEXIST Function: UNIX in SAS Companion for UNIX Environments
FILEEXIST Function: z/OS in SAS Companion for z/OS

Syntax

FILEEXIST(file-name)

Required Argument

file-name

is a character constant, variable, or expression that specifies a fully qualified physical filename of the external file in the operating environment.

Details

FILEEXIST returns 1 if the external file exists and 0 if the external file does not exist. The specification of the physical name for file-name varies according to the operating environment.
Although your operating environment utilities might recognize partial physical filenames, you must always use fully qualified physical filenames with FILEEXIST.

Example

This example verifies the existence of an external file. If the file exists, FILEEXIST opens the file. If the file does not exist, FILEEXIST displays a message in the SAS log. Note that in a macro statement that you do not enclose character strings in quotation marks.
%if %sysfunc(fileexist(&myfilerf)) %then
    %let fid=%sysfunc(fopen(&myfilerf));
%else
   %put The external file &myfilerf does not exist.;