BookmarkSubscribeRSS Feed
StickyRoll
Fluorite | Level 6

I have a script that needs to read the unix directory information such as path and the last modified date.

 

filename filelist pipe "ls -lrtd /sas/data/master/*/";

data directory_raw;
infile filelist truncover;
input filename $1000.;
run;

The script will first list out all files and folders from the directory /sas/data/master/*/

What I actually want to achieve here is to find what is inside /sas/data/master/*/*

I created this thread to seek help for allowing me to scan the files in the directory, scan for its last modified date and delete it if it exceeded 30 days. To do so, I need to first identify each and every files and folders' last modified date.

 

Since it is a ls command in unix, I have limited control. Notice that I want to actually drill down into the the second * in the unix directory. Is there anyone that can assist for me to identify the last modified date from unix directory (at least)?

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

Another solution maybe:

filename filelist pipe "ls -lrtd /sas/data/master/*/ && ls -lrtd /sas/data/master/*/*/";

Unsure that'd work, my unix shell knowledge has not been used for a long time.

Kurt_Bremser
Super User

Try this:

filename filelist pipe "find /sas/data/master -type f -mtime +30 -print 2>&1";

data directory_raw;
infile filelist truncover;
input filename $1000.;
run;

Once you have verified that it works correctly, you can expand the external command to

find /sas/data/master -type f -mtime +30 -print -exec rm -f {} \;

so that it removes the files also.

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
  • 964 views
  • 2 likes
  • 3 in conversation