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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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