Return to Archive

SAS Tip of the Month
January 2010

How can an external file be deleted using SAS? One way is to use the 'X' command and use a system command like 'DEL' in DOS. But another way is to use the FDELETE function inside a datastep as the following example demonstrates:

   data _null_;

      ** Assign the external file being deleted to a reference 'fn' using
         the FILENAME statement;

      ** Now delete the file using the FDELETE statement -- if RC does
         not equal zero then there is an issue;
      if rc=0 then put "File deleted";
      else put "ERR" "OR: Issue with trying to delete the file";

      ** Clear the FILENAME reference 'fn';


In the example the dataset DMEXT.TXT in the directory C:\TEMP is deleted -- there is also an additional piece of code that puts out a message as to whether there is an issue with the deleting of the file or not.

Hope this helps. Have a very good 2010.

Updated January 1, 2010