Deleting datasets more than a month old

[This site is not connected with the SAS Institute]

[last updated - 29 August 2003]

CRDATE

Because you do not see this field in your SAS datasets, SAS programmers tend to forget that it is available for them to use. CRDATE is a datetime stamp for when a dataset is created. There is another datetime stamp called MODATE for when the dataset was last modified. CRDATE is very useful when it comes to managing a library of datasets that get updated on a regular basis, such as once a week, where you have to roll off old data. You can obtain the value of this variable from the sashelp.vtable view or the dictionary.tables SQL view.

In the following code, datasets in a library called SASLIB will be identified if the creation date is more than 27 days older than the date of the SAS job and will be deleted.

%let lastmonth=;

proc sql;
  select memname into :lastmonth separated by ' '
  from dictionary.tables
  where libname='SASLIB' and today()-datepart(crdate) > 27;
quit;
run;

proc datasets nolist lib=SASLIB;
  delete &lastmonth;
run;
quit;

CRDATE/CRDTE and MODATE/MODTE

Just to confuse matters, SAS have got two forms of spelling for these two variables. If you use the attrn function to give you numeric information about a dataset then instead of MODATE you use MODTE and instead of CRDATE you use CRDTE. I have two macros for extracting this information using the attrn function called modte and crdte. But you would probably be better off just extracting this information from dictionary.tables like I did in the code above.

Go back to the home page.

E-mail the macro and web site author.