09-28-2011 06:10 PM
What have you got against proc delete? Do you also want to avoid proc datasets? Based on which operating system you're on would one of the system commands (e.g., x), together with your operating system delete command, be more preferable? Or were you looking for something else altogether?
Here is an alternative that Tom posted on SAS-L a couple of years ago:
%if %sysfunc(exist(&dsn,data)) %then %do;
drop table &dsn;
%if %sysfunc(exist(&dsn,view)) %then %do;
drop view &dsn;
09-28-2011 06:34 PM
Hey Art!, thanks for responding, I guess I should have been more specific...
I love Proc delete!, but it won't work on a "locked" data set
Problem is each night there is some sort of back up running and the data set becomes locked and I need to overwrite it (every night) and the SAS process fails to overwrite as it says the file is locked. I can however, go in and manually delete the data set in windows explorer and then recreate it, but I want to be able to either overwrite the existing one, or delete the old one first (from a locked state) and recreate it.
09-28-2011 07:05 PM
You'll have to forgive my ignorance on this, but what do you mean by check your options: xcmd, xsync, xwait? How do I do that?
I should state I'm doing all this in SAS EG but within actual code.
09-28-2011 07:16 PM
array opt $5 ('xcmd' 'xsync' 'xwait');
do i=1 to 3;
call execute('proc options option=' || strip(opt) || '; run;');
xcmd is the most important. If it is not defined you, or your sas administator will have to enable it in the config file for the server you are connecting to. It is probably not enabled for a reason, which means you are out of luck...
09-28-2011 07:34 PM
Thanks again Art and FriedEgg. Looks like it's not defined. I looked at the link Art and it's certainly helpful. Option 2 won't fly for sure, and option 1 requires me to gain admin rights which they will want to know what for so I'm not sure they'll let me go about it that way either. Appreciate the help!
09-29-2011 07:24 AM
I don't know how you can unlock a file that is opened in some other task.
What you might be able to do is code a loop that exits once you can lock the file for your session.
The LOCK statement is documented at http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/a001517609.htm
09-29-2011 08:33 AM
Throwing in my 2 cents worth....
It looks like you need to delete the entire dataset rather than a single SAS table. My first course of action would be to identify who has the lock on the file, otherwise we have had success just running a DOS command to delete the file at the appropriate time.
Here is a sample where we clean out a dataset of all html files before rewriting them. This could be easily change to delete the entire file. Just run the macro with the name of the file:
%let delcmd1 = DEL "&prefix.\*.html ";
%put deleting &filen data;