DATASETS Procedure

DELETE Statement

Deletes SAS files from a SAS library.
Manipulating SAS Files

Syntax

Required Argument

SAS-file-1 <...SAS-file-n>
specifies one or more SAS files that you want to delete. If the SAS file has an ALTER= password assigned, it must be specified in order to delete the SAS file. You can also use a numbered range list or colon list. For more information, see “Data Set Lists” in the SAS Language Reference: Concepts.

Optional Arguments

ALTER=alter-password
provides the Alter password for any alter-protected SAS files that you want to delete. You can use the option either in parentheses after the name of each SAS file or after a forward slash.
GENNUM=ALL | HIST | REVERT | integer
restricts processing for generation data sets. You can use the option either in parentheses after the name of each SAS file or after a forward slash. The following is a list of valid values:
ALL
refers to the base version and all historical versions in a generation group.
HIST
refers to all historical versions, but excludes the base version in a generation group.
REVERT | 0
deletes the base version and changes the most current historical version, if it exists, to the base version.
integer
is a number that references a specific version from a generation group. Specifying a positive number is an absolute reference to a specific generation number that is appended to a data set's name (that is, gennum=2 specifies MYDATA#002). Specifying a negative number is a relative reference to a historical version in relation to the base version, from the youngest to the oldest (that is, gennum=-1 refers to the youngest historical version).
MEMTYPE=mtype
restricts processing to one member type. You can use the option either in parentheses after the name of each SAS file or after a forward slash.
Alias:MT=, MTYPE=
Default:DATA

Details

The Basics

SAS immediately deletes SAS files when the RUN group executes. You do not have an opportunity to verify the delete operation before it begins.
If the SAS file has an ALTER= password assigned, it must be specified in order to delete the SAS file.
If you attempt to delete a SAS file that does not exist in the procedure input library, PROC DATASETS issues a message and continues processing. If NOWARN is used, no message is issued.
When you use the DELETE statement to delete a data set that has indexes associated with it, the statement also deletes the indexes.
You cannot use the DELETE statement to delete a data file that has a foreign key integrity constraint or a primary key with foreign key references. For data files that have foreign keys, you must remove the foreign keys before you delete the data file. For data files that have primary keys with foreign key references, you must remove the foreign keys that reference the primary key before you delete the data file.

Working with Generation Groups

Overview of Working with Generation Groups

When you are working with generation groups, you can use the DELETE statement to delete the following versions:
  • delete the base version and all historical versions
  • delete the base version and rename the youngest historical version to the base version
  • delete an absolute version
  • delete a relative version
  • delete all historical versions and leave the base version

Deleting the Base Version and All Historical Versions

The following statements delete the base version and all historical versions where the data set name is A:
proc datasets;
   delete A(gennum=all);

proc datasets;
   delete A / gennum=all;

proc datasets gennum=all;
   delete A;
The following statements delete the base version and all historical versions where the data set name begins with the letter A:
proc datasets;
   delete A:(gennum=all);

proc datasets;
   delete A: / gennum=all;

proc datasets gennum=all;
   delete A:;

Deleting the Base Version and Renaming the Youngest Historical Version to the Base Version

The following statements delete the base version and rename the youngest historical version to the base version, where the data set name is A:
proc datasets;
   delete A(gennum=revert);

proc datasets;
   delete A / gennum=revert;

proc datasets gennum=revert;
   delete A;
The following statements delete the base version and rename the youngest historical version to the base version, where the data set name begins with the letter A:
proc datasets;
   delete A:(gennum=revert);

proc datasets;
   delete A: / gennum=revert;

proc datasets gennum=revert;
   delete A:;

Deleting a Version with an Absolute Number

The following statements use an absolute number to delete the first historical version:
proc datasets;
   delete A(gennum=1);

proc datasets;
   delete A / gennum=1;

proc datasets gennum=1;
   delete A;
The following statements delete a specific historical version, where the data set name begins with the letter A:
proc datasets;
   delete A:(gennum=1);

proc datasets;
   delete A: / gennum=1;

proc datasets gennum=1;
   delete A:;

Deleting a Version with a Relative Number

The following statements use a relative number to delete the youngest historical version, where the data set name is A:
proc datasets;
   delete A(gennum=-1);

proc datasets;
   delete A / gennum=-1;

proc datasets gennum=-1;
   delete A;
The following statements use a relative number to delete the youngest historical version, where the data set name begins with the letter A:
proc datasets;
   delete A:(gennum=-1);

proc datasets;
   delete A: / gennum=-1;

proc datasets gennum=-1;
   delete A:;

Deleting All Historical Versions and Leaving the Base Version

The following statements delete all historical versions and leave the base version, where the data set name is A:
proc datasets;
   delete A(gennum=hist);

proc datasets;
   delete A / gennum=hist;

proc datasets gennum=hist;
   delete A;
The following statements delete all historical versions and leave the base version, where the data set name begins with the letter A:
proc datasets;
   delete A:(gennum=hist);

proc datasets;
   delete A: / gennum=hist;

proc datasets gennum=hist;
   delete A:;