Search code examples
sassas-macro

How to obtain the date of a most recently created dataset in SAS libname


I am trying to write some code that will look at all the datasets in a libname and bring back the created date of the most recently created file.

I have googled this for an entire day and cannot find a way to do this. I know that ATTRN can determine the created date of a dataset:

%let data_set = libname.data_set_name;
%let dsid = %sysfunc (open(&data_set));
%let create_date = %sysfunc(attrn(&dsid, crdte));

But there seems to be no way to make it look at multiple datasets so that a max date can be determined.

Can anyone please help?


Solution

  • OK, so I eventually found this bit of code in "Get Control of Your Input: Refer to Multiple Data Files Efficiently" a paper by Zhongping Zhai, Bloomington, IL and this works nicely for me:

    proc sql;
        create table all_datasets as
        select memname, crdate
        from dictionary.tables
        where libname="LIBNAME" and memname like "DSN%";
    quit;
    

    Hope this helps someone else too!