SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Need a SAS Macro to delete 5 days older files from folder.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Need a SAS Macro to delete 5 days older files from folder.

[ Edited ]

I need to delete 5 days older log files from a folder.I need to do from SAS EG and need a SAS macro.Unix command not required only SAS coding.


Accepted Solutions
Solution
‎06-26-2016 07:10 AM
Super Contributor
Posts: 408

Re: Need a SAS Macro to delete 5 days older files from folder.

You can easily get a directory listing in either of two ways:

 

1) Use e.g. the code as in this 2012 SGF paper. The trick is to assign a filename to a directory:

 

filename mydir "/my/logdir";

This will allow you to get filenames and filter them. Caveat here is that on Linux the FINFO() does not give you a creation date.  So it is required that the filename contains a date- and timestamp (which is a good habit for log files anyway). If so, parse the filename and use FDELETE() if it matches the 5-day criterium.

 

2) Use the Linux command ls in a pipe: 

 

filename dirlist pipe "ls -l yourlogdir" ;

Many variations can be chosen even up to use of find with the mtime / ctime options to directly only return the files older than 5 days. And heck, find can even delete them so SAS will not be involved at all. But this seems to be against your requirement of not using Linux commands. Also it could be that your workspace server run with -noxcmd, defeating this option entirely.

 

So easiest way would be to challenge the "no Linux command" restriction. Otherwise let's hope a date and time are in the filename.

 

Hope this helps,

- Jan.

View solution in original post


All Replies
Super User
Posts: 5,255

Re: Need a SAS Macro to delete 5 days older files from folder.

Check out the external files function category.
Is the date reflected on the file name?
If not, you need to extract file attribute information.
Data never sleeps
Super User
Posts: 17,774

Re: Need a SAS Macro to delete 5 days older files from folder.

I don't know of a way to extract file information without using Unix functions Smiley Sad

 

FDELETE will delete files once you identify them though. 

 

This really is a job for a clean up script though, similar to cleanwork utility from SAS. Probably worth looking at to see if it can help you?

 

http://support.sas.com/documentation/cdl/en/hostunx/67929/HTML/default/viewer.htm#n13ozwpq7az8v6n1s7...

Solution
‎06-26-2016 07:10 AM
Super Contributor
Posts: 408

Re: Need a SAS Macro to delete 5 days older files from folder.

You can easily get a directory listing in either of two ways:

 

1) Use e.g. the code as in this 2012 SGF paper. The trick is to assign a filename to a directory:

 

filename mydir "/my/logdir";

This will allow you to get filenames and filter them. Caveat here is that on Linux the FINFO() does not give you a creation date.  So it is required that the filename contains a date- and timestamp (which is a good habit for log files anyway). If so, parse the filename and use FDELETE() if it matches the 5-day criterium.

 

2) Use the Linux command ls in a pipe: 

 

filename dirlist pipe "ls -l yourlogdir" ;

Many variations can be chosen even up to use of find with the mtime / ctime options to directly only return the files older than 5 days. And heck, find can even delete them so SAS will not be involved at all. But this seems to be against your requirement of not using Linux commands. Also it could be that your workspace server run with -noxcmd, defeating this option entirely.

 

So easiest way would be to challenge the "no Linux command" restriction. Otherwise let's hope a date and time are in the filename.

 

Hope this helps,

- Jan.

Occasional Contributor
Posts: 17

Re: Need a SAS Macro to delete 5 days older files from folder.

Thank you very much jan.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 557 views
  • 2 likes
  • 4 in conversation