From: lblaketwo on
I am trying to develop SAS code that will test to see if a SAS data
library has datasets in it. If it does, then I want for SAS to delete
the datasets. Has anyone attempted to do this? If so, can you give
me a hand? Thanks!

From: shiling99 on
You always kick off a proc datasets to delete a dataset. The proc will
delete the file if it exists, otherwise just do nothing. The log will
show as below if it does not exist.

proc datasets;
delete ttt;
quit;

NOTE: The file WORK.TTT (memtype=DATA) was not found, but appears on a
DELETE statement.
NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

If you want to check the existence first, you may use exist function
and condistional execute the proc datasets upon the return-code of
exist function. Here is a sample pgm.

libname s 'c:\temp';

data s.a;
run;

%macro deldataset(lib=,dsn=);
%if %sysfunc(exist(&lib..&dsn)) %then
%str(proc datasets lib=&lib;
delete &dsn;
quit;)
;
%else %put dataset=&lib..&dsn does not exist!;
%mend;

%deldataset(lib=s,dsn=a)
%deldataset(lib=s,dsn=b);

HTH


On Feb 12, 10:05 am, lblake...(a)hotmail.com wrote:
> I am trying to develop SAS code that will test to see if a SAS data
> library has datasets in it. If it does, then I want for SAS to delete
> the datasets. Has anyone attempted to do this? If so, can you give
> me a hand? Thanks!


From: tanwan on
Something like:
proc datasets lib=poject7 kill memtype=data;
quit;
will delete all SAS datasets.
If none exists it will do nothing.


From: Richard A. DeVenezia on
tanwan wrote:
> Something like:
> proc datasets lib=poject7 kill memtype=data;
> quit;
> will delete all SAS datasets.
> If none exists it will do nothing.

Note that when tables have referential constraints, KILL will not delete
them. SASHELP.VREFCON, or DESCRIBE TABLE CONSTRAINTS or Proc DATASETS,
CONTENTS statement will list referential constraints.

Example
-----
proc sql;
create table One
( OneId num primary key
, OneData char
);
create table Two
( TwoId num primary key
, TwoData char
, OneId num references One(OneId)
);
quit;

proc datasets nolist lib=work kill memtype=data;
quit;

* After referential constraints are removed, DATASETS will
* be able to remove the tables;

proc sql;
alter table Two drop foreign key _FK0001_;
quit;

proc datasets nolist lib=work kill memtype=data;
quit;


--
Richard A. DeVenezia
http://www.devenezia.com/