Help using Base SAS procedures

how to delete a SAS file without using PROC DELETE

Reply
Contributor
Posts: 42

how to delete a SAS file without using PROC DELETE

Anyone have any code that can be used to delete a file that does not involve using proc delete?

thanks!

PROC Star
Posts: 7,492

Re: how to delete a SAS file without using PROC DELETE

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;

Trusted Advisor
Posts: 1,301

how to delete a SAS file without using PROC DELETE

proc datasets library=word; /* you could also use the kill option to delete all datasets from a library */

  delete blah;

run;

Trusted Advisor
Posts: 1,301

how to delete a SAS file without using PROC DELETE

Side note... Guessing from you name, are you in Colorado?  I am in Boulder.

Contributor
Posts: 42

Re: how to delete a SAS file without using PROC DELETE

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 Smiley Sad

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.

Trusted Advisor
Posts: 1,301

Re: how to delete a SAS file without using PROC DELETE

x rm -f /location/of/file; /* exact sytax would differ by operating system */

Contributor
Posts: 42

Re: how to delete a SAS file without using PROC DELETE

Tried that FriedEgg, and got the following:

ERROR: Shell escape is not valid in this SAS session.

Trusted Advisor
Posts: 1,301

how to delete a SAS file without using PROC DELETE

Check your options: xcmd, xsync, xwait

Contributor
Posts: 42

how to delete a SAS file without using PROC DELETE

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. 

PROC Star
Posts: 7,492

how to delete a SAS file without using PROC DELETE

Trusted Advisor
Posts: 1,301

how to delete a SAS file without using PROC DELETE

Good information Art.  I cannot claim to be very familiar with EG administation (even though I do it sometimes, yikes!)

Trusted Advisor
Posts: 1,301

how to delete a SAS file without using PROC DELETE

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... Smiley Sad

Contributor
Posts: 42

how to delete a SAS file without using PROC DELETE

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!

Valued Guide
Posts: 2,177

how to delete a SAS file without using PROC DELETE

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

Super Contributor
Posts: 358

Re: how to delete a SAS file without using PROC DELETE

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;

Ask a Question
Discussion stats
  • 14 replies
  • 927 views
  • 0 likes
  • 5 in conversation