The data used are either empty SAS tables created for the example, or information from the system library 'sashelp'.
1 Code Block
DATA STEP | MACRO Data
Explanation : This block initializes three empty SAS tables named `ds1`, `ds2`, and `some_other_ds` in the 'WORK' library. It then calls the `%delete_dataset` macro to delete these specific tables by name. This demonstrates targeted table deletion.
Explanation : This block creates three empty SAS tables: `ds_1`, `ds_2`, and `ds_3`. The `%delete_dataset` macro is then used with the `pattern = "/ds_/"` parameter to delete all tables in the 'WORK' library whose name contains the string 'ds_', illustrating deletion based on regular expressions.
Copied!
data ds_1 ds_2 ds_3;
run;
%delete_dataset(
pattern = "/ds_/"
);
1
DATA ds_1 ds_2 ds_3;
2
RUN;
3
4
%delete_dataset(
5
pattern = "/ds_/"
6
);
3 Code Block
PROC SQL | LIBNAME | DATA STEP | MACRO Data
Explanation : This block dynamically retrieves the physical path of the 'WORK' library using `PROC SQL` and the `sashelp.vslib` table. It then defines a new temporary libname named `tmp` pointing to this path. An empty table `ds1` is created in this new `tmp` libname. Finally, the `%delete_dataset` macro is invoked to delete `ds1` specifically from `tmp`, and the `tmp` libname is cleared. This shows how to target deletions in libraries other than 'WORK'.
Copied!
proc sql noprint;
select path into :path
from sashelp.vslib
where libname = "WORK";
quit;
libname tmp "%trim(&path)";
data tmp.ds1;
run;
%delete_dataset(
libname = tmp,
dataset = ds1
);
libname tmp clear;
1
PROC SQL noprint;
2
select path into :path
3
from sashelp.vslib
4
where LIBNAME = "WORK";
5
QUIT;
6
7
LIBNAME tmp "%trim(&path)";
8
9
DATA tmp.ds1;
10
RUN;
11
12
%delete_dataset(
13
LIBNAME = tmp,
14
dataset = ds1
15
);
16
17
LIBNAME tmp clear;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.