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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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