Published on :
Utility EXTERNE

Utility macro to delete a file

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
The `di_util_del_file` macro takes a `file` parameter representing the full path of the file to be deleted. It first checks for the file's existence using `%sysfunc(fileexist)`. If the file exists, it assigns a temporary fileref (`temp`) to it with `%sysfunc(filename)` and then deletes it with `%sysfunc(fdelete)`. If the file does not exist, an informational message is written to the SAS© log.
Data Analysis

Type : EXTERNE


The macro operates on a file specified by its path, which is an external resource to the SAS program itself. No SASHELP data is used or created internally.

1 Code Block
MACRO di_util_del_file
Explanation :
This block defines the `di_util_del_file` macro. It uses the `%sysfunc(fileexist(...))` function to check if the file specified by the `file` parameter exists. If it does, it uses `%sysfunc(filename(...))` to assign a logical 'fileref' to the file, then `%sysfunc(fdelete(...))` to delete it from the file system. If the file does not exist, a message is sent to the SAS log via `%put`.
Copied!
1%macro di_util_del_file(file=);
2 %IF %sysfunc(fileexist(&file)) ge 1 %THEN %DO;
3 %let rc=%sysfunc(filename(temp,&file));
4 %let rc=%sysfunc(fdelete(&temp));
5 %END;
6 %ELSE %put The file &file does not exist;
7%mend di_util_del_file;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.