Anyone have any code that can be used to delete a file that does not involve using proc delete?
thanks!
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:
%macro deletedsn(dsn);
%if %sysfunc(exist(&dsn,data)) %then %do;
proc sql;
drop table &dsn;
quit;
%end;
%if %sysfunc(exist(&dsn,view)) %then %do;
proc sql;
drop view &dsn;
quit;
%end;
%mend deletedsn;
proc datasets library=word; /* you could also use the kill option to delete all datasets from a library */
delete blah;
run;
Side note... Guessing from you name, are you in Colorado? I am in Boulder.
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.
x rm -f /location/of/file; /* exact sytax would differ by operating system */
Tried that FriedEgg, and got the following:
ERROR: Shell escape is not valid in this SAS session.
Check your options: xcmd, xsync, xwait
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.
Good information Art. I cannot claim to be very familiar with EG administation (even though I do it sometimes, yikes!)
data _null_;
array opt[3] $5 ('xcmd' 'xsync' 'xwait');
do i=1 to 3;
call execute('proc options option=' || strip(opt) || '; run;');
end;
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...
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!
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
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:
%macro deletefile(filen);
%let delcmd1 = DEL "&prefix.\*.html ";
%put deleting &filen data;
data _null_;
X &delcmd1;
run;
%mend;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.