Date: Fri, 14 Jan 2011 07:58:27 -0500
Reply-To: Michael Raithel <michaelraithel@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Michael Raithel <michaelraithel@WESTAT.COM>
Subject: Re: Files in a directory (without X)
Content-Type: text/plain; charset="us-ascii"
John posted the following:
> I'm using the enterprise guide so I can't use the X command or pipe
> statement but I'd like to use my SAS program to delete the files in a
> certain directory. I found a useful paper
> "http://www2.sas.com/proceedings/forum2007/054-2007.pdf" on using
> DREAD, etc. that provides a solution that ALMOST works. The problem
> is, it doesn't distinguish between files and directories. I've
> searched the SAS documentation but I can't find a way to either
> restrict DREAD to files or to distinguish between files and
> Here's an example gleaned from Linda Libeg's paper:
> filename dirlist "C:\logs";
> %macro ttt(libref);
> %let dirid = %sysfunc(DOPEN(&libref));
> /* "dircnt" contains the number of files in the directory */
> %let dircnt = %sysfunc(DNUM(&dirid));
> %do i = 1 %to &dircnt;
> %let dirread = %sysfunc(DREAD(&dirid,&i));
> %put dirread = &dirread;
> %let rc =%sysfunc(DCLOSE(&dirid));
> This works, but &dirread can be a file or a subdirectory. Does anyone
> know a way to restrict it to files onlt?
John, nice to see Linda's name in BIG LIGHTS; because I love that paper of hers!
Coming up for air from some heavy SAS Mecca assignments, I am only just catching up with this thread. I see that you have received a lot of feedback, but am not sure if you got your answer or not. If not, consider my own way of identifying and deleting files without using the X command. It can be found in my old SUGI 30 paper:
Automatically Process a Varying Number of New Data Files From a "Data Directory"
If you already have a solution, then this can simply be another SAS file manipulation arrow in your SAS toolkit quiver!
John, best of luck in all your SAS endeavors!
I hope that this suggestion proves helpful now, and in the future!
Of course, all of these opinions and insights are my own, and do not reflect those of my organization or my associates. All SAS code and/or methodologies specified in this posting are for illustrative purposes only and no warranty is stated or implied as to their accuracy or applicability. People deciding to use information in this posting do so at their own risk.
Michael A. Raithel
"The man who wrote the book on performance"
Author: Tuning SAS Applications in the MVS Environment
Author: Tuning SAS Applications in the OS/390 and z/OS Environments, Second Edition
Author: The Complete Guide to SAS Indexes
A lie gets halfway around the world before the truth has a chance to get its pants on. - Winston Churchill