Date: Thu, 28 Jan 2010 19:22:59 -0500
Reply-To: Ya Huang <ya.huang@AMYLIN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ya Huang <ya.huang@AMYLIN.COM>
Subject: Re: Reliable way to create/delete hundreds of folders/files
Hi Michael,
If I understand your suggestion correctly, you mean to do a paired
operation, ie. always try to delete a folder before create it. I think
it may work, I'll give it a try.
But I think this approach has one drawback: there might be some
folders from previous run not getting removed.
Ya
On Thu, 28 Jan 2010 18:45:30 -0500, Michael Raithel
<michaelraithel@WESTAT.COM> wrote:
>Dear SAS-L-ers,
>
>Ya Huang posted the following:
>
>> Hi there,
>>
>> The following code shows how I create/delete hundreds of folders and
>> files.
>> The problem is that it is not very reliable, sometimes
>> a few folders won't be created, which cause code followed it
>> stop running:
>>
>> data _null_;
>> set dd;
>> file "%sysfunc(pathname(work))\md.bat";
>> if _n_=1 then put 'rd/q/s "H:\My Documents"\.';
>> put 'md "H:\My Documents"\D' n_;
>> run;
>>
>> options noxwait xsync;
>> x """%sysfunc(pathname(work))\md.bat""";
>>
>> code for creating files in corresponding folders....
>>
>> Dataset dd has one variable n_, which is integer number, but not
>> necessary
>> consecutive. Each time the program run, n_ may be different, which
>> means
>> new set of folders has to be created. Before the new set of folders are
>> created, the old folders has to be deleted, along with all the files in
>> there. The numbers of files in each folder varies, from one to a few
>> thousands. First thing the above code do is to clean up all old
>> folders/files (with rd/q/s command). It may takes several minutes, then
>> create new folders.
>>
>> It seems to me that some of the md command is executed before the rd is
>> run, therefore, the newly created folder is deleted right after it is
>> created.
>>
>> Any better way to do this?
>>
>Ya, nice question! I have another way to do this. It can only be judged
to be "better" if it solves your problem:-)
>
>Try this close-but-untested code:
>
>options xsync noxwait;
>
>data _null_;
>
> set dd;
>
> file "%sysfunc(pathname(work))\md.bat";
>
> if _n_=1 then do;
>
> put 'rd/q/s "H:\My Documents"\.';
>
> call system(""%sysfunc(pathname(work))\md.bat"")
>
> put 'md "H:\My Documents"\D' n_;
>
> call system(""%sysfunc(pathname(work))\md.bat"")
>
> end;
>
><<Ya's other SAS code>>
>
>run;
>
>The point of the example is that since you have the XSYNC option
specified, you can execute the .bat file twice in the same DATA step via
CALL SYSTEM and it will dutifully wait for the directories to be deleted
before attempting to create new ones in their place.
>
>Monkey around with the code idea, above, and let us know if it works... or
even better, if it is better!
>
>Ya, 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"
>E-mail: MichaelRaithel@westat.com
>
>Author: Tuning SAS Applications in the MVS Environment
>
>Author: Tuning SAS Applications in the OS/390 and z/OS Environments,
Second Edition
>http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=58172
>
>Author: The Complete Guide to SAS Indexes
>http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=60409
>
>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>...it's only rock and roll but I like it... - Rolling Stones
>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|