Friday, July 19, 2013

SAS: Permissive Delete

I recently had a lot of problems with evening processes failing due to lack of disk space:

ERROR: Insufficient space in file PERM.SRA_ANALYTICS_DSS_T.DATA.
ERROR: File PERM.SRA_ANALYTICS_DSS_T.DATA is damaged. I/O processing did not complete.

My project leader pointed out the following:

From the web… SAS does not overwrite datasets at once, but creates a copy and after successful end of a step, the old dataset is deleted and the intermediate file is renamed.

He suggested we delete the file before attempting to write the new one.  So I wrote a macro to conditionally delete the file.  Back in the old days, some of use mainframers called this a "permissive delete", hence the name of the macro.

Here's the macro:

%if %sysfunc(exist(&SASFILE)) %then %do;
    proc sql noprint;
    drop table &SASFILE;
    %put *** File &SASFILE deleted.;
%else %do;
    %put *** File &SASFILE already deleted.;

Here's the test program:

libname Perm "C:\TEMP";
%let TBL_MY_FILE = Perm.Junk;

data &TBL_MY_FILE;
name = "Bill";
age = 56;

proc print data=&TBL_MY_FILE;

* Should delete ;

* Should be gone already ;

Here's the significant portion of the log:

25   * Should delete ;
NOTE: Table PERM.JUNK has been dropped.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds

*** File Perm.Junk deleted.
28   * Should be gone already ;
*** File Perm.Junk already deleted.