Search notes:

SAS programming, function fdelete

The following example uses fexist to check whether a file exists. If this is the case, it deletes it using fdelete.
Note: fdelete and fexist operate on filerefs, not on physical operating system path names. Therefore, the macro also uses a filename statement to assign the filref.
%macro deleteFile(fileName);
  filename fnam "&fileName";
  data _null_;
    if fexist("fnam") then do;
       put "&fileName exists, going to delete it.";
       rc = fdelete("fnam");
    end;
    else do;
       put "&fileName does not exist.";
       put "Nothing to do!";
    end;
  run;
  filename fnam clear;
%mend  deleteFile;

systask command "touch /tmp/tq84.txt" wait;
%deleteFile(/tmp/tq84.txt)
%deleteFile(/tmp/tq84.txt)
Github repository about-SAS, path: /programming/functions/fdelete/delete-file-if-it-exists.sas

See also

functions

Index