f



SAS Macro to delete a SAS dataset


Here=92s a simple SAS Macro to delete a SAS dataset=85It takes the name of
the SAS dataset as the parameter=85

%macro deletedsn(dsname);

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

proc datasets lib=3D&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


0
SAS
12/2/2009 4:50:34 PM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

3 Replies
971 Views

Similar Articles

[PageSpeed] 46

Try the SCL version...

delete(symget('sasDatasetName'));

You could embed the delete function within sysfunc too.
0
montura
12/2/2009 5:49:39 PM
SCL function delete does not work with %SYSFUNC (tested in SAS 9.2).
You could use PROC DELETE data=3D, 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=3D1; 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=3Dxx; x=3D1; 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.

On Dec 2, 12:49=A0pm, montura <montura...@gmail.com> wrote:
> Try the SCL version...
>
> delete(symget('sasDatasetName'));
>
> You could embed the delete function within sysfunc too.

0
Tom
12/2/2009 6:07:34 PM
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.
0
montura
12/2/2009 6:44:11 PM
Reply: