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:

%macro PERMISSIVE_DELETE(SASFILE=);
%if %sysfunc(exist(&SASFILE)) %then %do;
    proc sql noprint;
    drop table &SASFILE;
    quit;
    run;
    %put *** File &SASFILE deleted.;
%end;
%else %do;
    %put *** File &SASFILE already deleted.;
%end;
%mend PERMISSIVE_DELETE;


Here's the test program:

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

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

proc print data=&TBL_MY_FILE;
run;

* Should delete ;
%PERMISSIVE_DELETE(SASFILE=&TBL_MY_FILE);

* Should be gone already ;
%PERMISSIVE_DELETE(SASFILE=&TBL_MY_FILE);


Here's the significant portion of the log:

24
25   * Should delete ;
26   %PERMISSIVE_DELETE(SASFILE=&TBL_MY_FILE);
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.
27
28   * Should be gone already ;
29   %PERMISSIVE_DELETE(SASFILE=&TBL_MY_FILE);
*** File Perm.Junk already deleted.