Return to Archive

SAS Tip of the Month
March 2007

Occasionally it is necessary to cleanup old datasets in a directory based on a date. The following SAS code is an example where datasets in the directory referenced by the LIBNAME OLDDATA that are older than 15MAR2007 are deleted:

    %let dslist=%str();
    proc sql;
        select memname into :dslist separated by ' '
          from sashelp.vtable
          where libname='OLDDATA' and
                datepart(crdate) "15MAR2007"d;
    proc datasets library="OLDDATA" nolist nodetails;
       delete &dslist

This code can be modified to any datasets in a specified directory as well as and date and/or time that the user may choose.

Updated March 1, 2007