Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
September 2015
(for SAS)

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;
      rc=FILENAME('fn',"c:\temp\dmext.txt");

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

      ** Clear the FILENAME reference 'fn';
      rc=FILENAME('fn');

   run;

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 was useful.

________________________________
Updated September 2, 2015