Published on :
Utility CREATION_INTERNE | SASHELP

SAS Tables Deletion Demonstration

This code is also available in: Deutsch Español Français
Awaiting validation
The script presents three scenarios for deleting SAS© tables: deleting specific tables by name, deleting tables matching a regular expression pattern, and deleting a table in a specified SAS© library (different from 'WORK'). It uses empty table creations for demonstration purposes and interacts with 'sashelp.vslib' to obtain library path information.
Data Analysis

Type : CREATION_INTERNE | SASHELP


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.
Copied!
1DATA ds1 ds2 some_other_ds;
2RUN;
3 
4%delete_dataset(
5 dataset = ds1 ds2 some_other_ds
6);
2 Code Block
DATA STEP | MACRO Data
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!
1DATA ds_1 ds_2 ds_3;
2RUN;
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!
1PROC SQL noprint;
2 select path into :path
3 from sashelp.vslib
4 where LIBNAME = "WORK";
5QUIT;
6 
7LIBNAME tmp "%trim(&path)";
8 
9DATA tmp.ds1;
10RUN;
11 
12%delete_dataset(
13 LIBNAME = tmp,
14 dataset = ds1
15);
16 
17LIBNAME 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.