BookmarkSubscribeRSS Feed
3 REPLIES 3
Patrick
Opal | Level 21

A subject line alone is insufficient to provide us with enough information for your question.

Please provide much more detailed information like: Are you talking about SAS tables in a library or some other files on the file system? Unix/Linux or Windows - OS? SAS version?

HOW does the naming pattern look like. Where is the date part in the name and what sort of logic would you required to delete the files (like: older than x days based on current system date)?

Provide some sample data / actual file names showing the actual naming pattern you're dealing with.

suhas1
Calcite | Level 5

i am having sas tables in a library.some filenames start like 15011990(ddmmyyyy)pattern.some filenames like custseg01 like that .i want to delete datesuffix files in that particular location


Thanks

Tom
Super User Tom
Super User

If the pattern as at the beginning it would be easier as SAS allows the use of colon as a wildcard for the end of a name.

To search for pattern at the end you will need to get the list of names as data and search that.

So you could use PROC CONTENTS output or the DICTIONARY.TABLES or DICTIONARY.MEMBERS metadata tables to get the names.

libname mylib 'my directory name';
proc contents data=mylib._all_ noprint out=contents; run;
data names ;
  set contents;
  by memname ;
  if first.memname;
  keep memname libname;
run;

Now that you have all of the names of the datasets in that directory.  You can then use some code to find the ones you want to delete and then generate code to delete them.  For example to delete any dataset where the last 8 characters are a valid date in DDMMYYYY style.

data _null_;
  set names ;
  if length(memname) > 8
  and input(substr(memname,length(memname-7)),??ddmmyy8.) ne . then do;
    call execute(catx(' ','proc delete data=',catx('.',libname,memname),';run;'));
  end;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1040 views
  • 0 likes
  • 3 in conversation