Discussion:
SAS Macro to delete a SAS dataset
(too old to reply)
SAS Techies
2009-12-02 16:50:34 UTC
Permalink
Here’s a simple SAS Macro to delete a SAS dataset…It takes the name of
the SAS dataset as the parameter…

%macro deletedsn(dsname);

%if %index(&dsname,'.') eq 0 %then %do; %let lib=work; %let
dsn=&dsname; %end;
%else %if %index(&dsname,'.') eq 0 %then %do; %let lib=%scan(&dsname,
1,'.'); %let dsn=%scan(&dsname,1,'.'); %end;

proc datasets lib=&lib nolist;
delete &dsn;
quit;
%mend deletedsn;

%deletedsn(new);
%deletedsn(somelib.new);

Read more @ http://sastechies.blogspot.com/2009/12/sas-macro-to-delete-sas-dataset.html
montura
2009-12-02 17:49:39 UTC
Permalink
Try the SCL version...

delete(symget('sasDatasetName'));

You could embed the delete function within sysfunc too.
Tom Abernathy
2009-12-02 18:07:34 UTC
Permalink
SCL function delete does not work with %SYSFUNC (tested in SAS 9.2).
You could use PROC DELETE data=, but I like to use PROC SQL to "drop"
tables and/or views.
You could re-code your macro as:

%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;


27 data xx; x=1; run;

NOTE: The data set WORK.XX has 1 observations and 1 variables.

28 %deletedsn(xx)
NOTE: Table WORK.XX has been dropped.

29
30 data xx/view=xx; x=1; run;

NOTE: DATA STEP view saved on file WORK.XX.
NOTE: A stored DATA STEP view cannot run under a different operating
system.

31 %deletedsn(xx)
NOTE: View WORK.XX has been dropped.
Post by montura
Try the SCL version...
delete(symget('sasDatasetName'));
You could embed the delete function within sysfunc too.
montura
2009-12-02 18:44:11 UTC
Permalink
class delete;
runInterface: method;
delete(symget('sasDatasetName'));
endmethod;
endclass;


Works fine if you use plain SCL.
you could also embed a Proc Datasets

class delete;
runInterface: method;
submit continue;
proc datasets lib=work kill nolist memtype=DATSA;

quit;
endsubmit;
endmethod;
endclass;


Either way, Macro is harder to read, write and understand.
oloolo
2009-12-02 17:26:59 UTC
Permalink
well, this one reminds me another thread recently discussed:

http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0911c&L=sas-l&F=&S=&P=4034
Here?s a simple SAS Macro to delete a SAS dataset?It takes the name of
the SAS dataset as the parameter?
%macro deletedsn(dsname);
%if %index(&dsname,'.') eq 0 %then %do; %let lib=work; %let
dsn=&dsname; %end;
%else %if %index(&dsname,'.') eq 0 %then %do; %let lib=%scan(&dsname,
1,'.'); %let dsn=%scan(&dsname,1,'.'); %end;
proc datasets lib=&lib nolist;
delete &dsn;
quit;
%mend deletedsn;
%deletedsn(new);
%deletedsn(somelib.new);
dataset.html
Wall, David K. (CDC/NIOSH/DSHEFS)
2009-12-02 21:27:58 UTC
Permalink
Post by montura
class delete;
runInterface: method;
delete(symget('sasDatasetName'));
endmethod;
endclass;
Works fine if you use plain SCL.
you could also embed a Proc Datasets
class delete;
runInterface: method;
submit continue;
proc datasets lib=work kill nolist memtype=DATSA;
quit;
endsubmit;
endmethod;
endclass;
Either way, Macro is harder to read, write and understand.
Except that I've never had a need to use SCL, whereas I use macros all
the time. Macros are easy for me to read, write and understand; SCL
might as well be another language. It rather looks like it is. Might
be fun to learn it even if I don't need it.
montura
2009-12-04 14:55:09 UTC
Permalink
Object code is easy.
It takes about 5 minutes to learn what you need to mentally "ignore",
like the class and method statements. Interesting that you say it
looks like another langugage - a large portion of The SAS System is
written in SCL.

I'll be posting SCL programming chapters on www.keystonesug.com.
Statisticians who are stuck in the past might find structured
programming techniques a little hard to pick up, after all, some
people are messy in their work habits as a general rule. Clean code is
just too much trauma. :o)

Fehd, Ronald J. (CDC/CCHIS/NCPHI)
2009-12-03 14:17:20 UTC
Permalink
From: SAS Techies
Subject: SAS Macro to delete a SAS dataset
Here's a simple SAS Macro to delete a SAS dataset...It takes the name
of
the SAS dataset as the parameter...
%macro deletedsn(dsname);
%if %index(&dsname,'.') eq 0 %then %do; %let lib=work; %let
dsn=&dsname; %end;
%else %if %index(&dsname,'.') eq 0 %then %do; %let lib=%scan(&dsname,
1,'.'); %let dsn=%scan(&dsname,1,'.'); %end;
proc datasets lib=&lib nolist;
delete &dsn;
quit;
%mend deletedsn;
%deletedsn(new);
%deletedsn(somelib.new);
you're working too hard, and providing slow code

proc delete is faster than either proc datasets or sql drop table:

http://www.sascommunity.org/wiki/PROC_Delete

Ron Fehd the module/routine/subroutine maven CDC Atlanta GA USA RJF2
at cdc dot gov
Data _null_;
2009-12-03 14:41:55 UTC
Permalink
I too like(d) PROC DELETE.

When I used it I was forced to remove it and use PROC DATASETS because
PROC DELETE is not documented.

Also, but I have not tested it. How does it work with indexed data
sets, audit trails, generation data groups, views, etc.?

I don't worry much about deleting, "all" of my programs run in batch
and are obsolete as soon as they are written.
Post by Fehd, Ronald J. (CDC/CCHIS/NCPHI)
From: SAS Techies
Subject: SAS Macro to delete a SAS dataset
Here's a simple SAS Macro to delete a SAS dataset...It takes the name
of
the SAS dataset as the parameter...
%macro deletedsn(dsname);
%if %index(&dsname,'.') eq 0 %then %do; %let lib=work; %let
dsn=&dsname; %end;
%else %if %index(&dsname,'.') eq 0 %then %do; %let lib=%scan(&dsname,
1,'.'); %let dsn=%scan(&dsname,1,'.'); %end;
proc datasets lib=&lib nolist;
delete &dsn;
quit;
%mend deletedsn;
%deletedsn(new);
%deletedsn(somelib.new);
you're working too hard, and providing slow code
http://www.sascommunity.org/wiki/PROC_Delete
Ron Fehd the module/routine/subroutine maven CDC Atlanta GA USA RJF2
at cdc dot gov
Søren Lassen
2009-12-04 07:06:48 UTC
Permalink
Proc delete cannot delete views (I just tried).

Of the macros suggested, I prefer the SQL version. The original
version does not work if the USER option is set to something other
than WORK.

Regards,
SÞren
Post by Data _null_;
I too like(d) PROC DELETE.
When I used it I was forced to remove it and use PROC DATASETS because
PROC DELETE is not documented.
Also, but I have not tested it. How does it work with indexed data
sets, audit trails, generation data groups, views, etc.?
I don't worry much about deleting, "all" of my programs run in batch
and are obsolete as soon as they are written.
Post by Fehd, Ronald J. (CDC/CCHIS/NCPHI)
From: SAS Techies
Subject: SAS Macro to delete a SAS dataset
Here's a simple SAS Macro to delete a SAS dataset...It takes the name
of
the SAS dataset as the parameter...
%macro deletedsn(dsname);
%if %index(&dsname,'.') eq 0 %then %do; %let lib=work; %let
dsn=&dsname; %end;
%else %if %index(&dsname,'.') eq 0 %then %do; %let lib=%scan(&dsname,
1,'.'); %let dsn=%scan(&dsname,1,'.'); %end;
proc datasets lib=&lib nolist;
delete &dsn;
quit;
%mend deletedsn;
%deletedsn(new);
%deletedsn(somelib.new);
you're working too hard, and providing slow code
http://www.sascommunity.org/wiki/PROC_Delete
Ron Fehd the module/routine/subroutine maven CDC Atlanta GA USA RJF2
at cdc dot gov
Loading...