PROC DATASETS - DELETE Statement

Setting up the Background

SAS Code:

libname xyz 'D:\SAS_Datasets\';

data xyz.a;

amt = 5600;

run;

data xyz.b;

run;

data xyz.c;

amt = 5600;

run;

data xyz.d;

amt = 5600;

run;

EXAMPLE:

Before moving to the actual demonstrations we will set up the environment.

Following code declares one library and creates some SAS datasets inside; just for demo purpose.

<< Back to the PROC DATASETS Page.

To delete the datasets from the library PROC DATASETS comes with DELETE statement, alternatively one can also use SAVE statement.

DELETE statement will delete the datasets from the specified library enlisted after the DELETE statement.

SAVE statement will delete all the datasets from the given library except those specifed by the SAVE statement.

SYNTAX:

proc datasets lib="libname";

DELETE list_of_datasets_to_be_deleted;

SAVE list_of_datasets_to_be_saved;

quit;

amt = 5600;

Now; lets see how one can use PROC DATASETS to delete the datasets from the library.

SAS Code: PROC DATASETS - DELETE and SAVE Statements

libname xyz 'D:\SAS_Datasets\';

proc datasets lib=xyz;

/* This will delete the dataset changed_a only */

delete a;

/* This will delete all the datasets except mentioned in the save statement */

save b;

quit;

proc datasets lib=xyz;

quit;

Following is the output of the code above. (Note, this is just a part of the actual output).

OUTPUT: PROC DATASETS - DELETE and SAVE Statements

We can see from the above output that; first statement; delete changed_a; has deleted the dataset from library.

And the second statement; save b; have caused to delete all other datasets except b. This is particularly useful when you have got big list of datasets to be deleted and relatively few datasets which needs to be kept. In that case one can just mention those dataset names instead of typing the whole list of datasets to be deleted.

PROC DATASETS>> CONETNTS MODIFY/RENAME/FORMAT APPEND COPY/MOVE DELETE KILL