PING  0.9
Statistical data handling and processing in production environment
file_check

Check the existence of a file given by its name. If required, also possibly check the format.

%let ans=%file_check(fn, ext=);

Arguments

  • fn : full path and name of external file (!not a fileref!);
  • ext : (option) string representing the extension of desired format (e.g., csv); if not set, the format of the file is not verified.

Returns

ans : error code associated to test, i.e.:

  • 0 if the file exists (with the right format when ext is not empty), or
  • 1 if the file does not exist, or
  • -1 if the file exists but the format is not the one specified by ext.

Example

Let us consider the file where this macro is defined, and check it actually exists:

%let fn=&G_PING_LIBAUTO/file_check.sas;
%let ans=%file_check(&fn, ext=SAS);

returns ans=0, while:

%let ans=%file_check(&fn, ext=TXT);

returns ans=-1.

Run macro %_example_file_check for more examples.

Note

In short, the error code returned when ext is not set is the evaluation of:

1 - %sysfunc(fileexist(&fn))

References

  1. "Check for existence of a file".
  2. Johnson, J. (2010): "OBJECT_EXIST: A macro to check if a specified object exists".

See also

%ds_check, %dir_check, %lib_check, %file_copy, %file_delete, %file_name, %file_ls, %file_move, FILEEXIST.