Published on :
Macro TRANSFORMATION

SAS Macro mp_dropmembers

This code is also available in: Deutsch Español Français
This macro, `mp_dropmembers`, is designed to safely delete SAS© tables (datasets) and/or views from a specified library. It includes a condition (`iftrue`) to allow conditional execution, and checks if the list of objects to be deleted is empty to avoid unnecessary actions. It uses `PROC DATASETS` with the `nolist` option to prevent excessive logging, and executes two `delete` commands: one for tables and one for views (`/mtype=view`), ensuring that both types of objects are processed if they exist without causing errors if a type is not present or if the object does not exist. The usage example demonstrates how to use it for temporary tables and views.
Data Analysis

Type : TRANSFORMATION


The `mp_dropmembers` macro is not intended to create new data or to directly read data from external sources or SASHELP. Its role is to manage and delete existing tables and views within a user-specified library (`libref`). Usage examples mention `sashelp.class` for creating temporary tables for demonstration purposes, but this does not constitute a direct dependency of the macro.

1 Code Block
MACRO mp_dropmembers
Explanation :
This block defines the `mp_dropmembers` macro with three parameters: `list` (list of objects to delete), `libref` (target library, default 'WORK'), and `iftrue` (execution condition, default '1=1'). The macro first checks the `iftrue` condition and exits if it is false. Then, it checks if the `list` of objects is empty using the `mf_isblank` macro; if so, it displays a note and exits. If the list is not empty, it uses `PROC DATASETS` to delete the objects. Two `DELETE` commands are used: one for tables and another for views (`/mtype=view`), ensuring robust deletion without generating errors if the object does not exist or is not of the specified type.
Copied!
1%macro mp_dropmembers(
2 list /* space separated list of datasets / views */
3 ,libref=WORK /* can only drop from a single library at a time */
4 ,iftrue=%str(1=1)
5)/*/STORE SOURCE*/;
6 
7 %IF not(%eval(%unquote(&iftrue))) %THEN %return;
8 
9 %IF %mf_isblank(&list) %THEN %DO;
10 %put NOTE: nothing to drop!;
11 %return;
12 %END;
13 
14 PROC DATASETS lib=&libref nolist;
15 delete &list;
16 delete &list /mtype=view;
17 RUN;
18%mend mp_dropmembers;
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.
Copyright Info : Copyright (c) 2001-2006 Rodney Sparapani. This file is free software distributed under the terms of the GNU General Public License (GPL) version 2 or later.