Previous Page | Next Page

Copying, Moving, and Deleting SAS Data Sets

Deleting SAS Data Sets


Specifying Data Sets to Delete

Use the DELETE statement to delete one or more data sets from a SAS data library. If you want to delete more than one data set, then simply list the names after the DELETE keyword with a blank space between the names, or use an abbreviated member list if applicable (such as YRDATA1-YRDATA5).

CAUTION:
SAS immediately deletes the files in a SAS data library when the program statements are submitted.

You are not asked to verify the delete operation before it begins, so be sure that you intend to delete the files before submitting the program.  [cautionend]

For example, the following program specifies USCLIM as the procedure input library, then deletes the data set RAIN from the library:

proc datasets library=usclim;
   delete rain;
run;

The following output shows that SAS sends messages to the SAS log when it processes the DELETE statement:

Deleting the Data Set RAIN from the Library USCLIM

212  proc datasets library=usclim;
                              -----Directory-----

                   Libref:            USCLIM                
                   Engine:            V8                    
                   Physical Name:     external-file
                   File Name:         external-file
                   Inode Number:      1864992               
                   Access Permission: rwxr-xr-x             
                   Owner Name:        userid                
                   File Size (bytes): 4096                  


                                       File
               #  Name      Memtype    Size  Last Modified
               -------------------------------------------------
               1  BASETEMP  CATALOG   20480   15NOV2000:14:38:35
               2  HIGHTEMP  DATA      16384   16NOV2000:12:14:50
               3  LOWTEMP   DATA      16384   16NOV2000:12:14:54
               4  RAIN      DATA      16384   16NOV2000:12:14:59
               5  REPORT    CATALOG   20480   15NOV2000:14:39:02
               6  TEMPCHNG  DATA      16384   15NOV2000:14:30:41
               7  USHIGH    DATA      16384   15NOV2000:14:26:48
               8  USLOW     DATA      16384   15NOV2000:14:30:08
213     delete rain;
214  run;
NOTE: Deleting USCLIM.RAIN (memtype=DATA).

Specifying Data Sets to Save

To delete all data sets but a few, you can use the SAVE statement to list the names of the data sets that you want to keep. List the data set names with a blank space between the names, or use an abbreviated member list (such as YRDATA1-YRDATA5) if applicable.

The following statements delete all the data sets except TEMPCHNG from the library USCLIM:

   save tempchng;
run;

The following output shows the SAS log from the delete operation. SAS sends messages to the SAS log, verifying that it has kept the data sets that you specified in the SAVE statement and deleted all other members of the library.

Deleting All Members of the Library USCLIM Except the Data Set TEMPCHNG

232     save tempchng;
233  run;
NOTE: Saving USCLIM.TEMPCHNG (memtype=DATA).
NOTE: Deleting USCLIM.BASETEMP (memtype=CATALOG).
NOTE: Deleting USCLIM.HIGHTEMP (memtype=DATA).
NOTE: Deleting USCLIM.LOWTEMP (memtype=DATA).
NOTE: Deleting USCLIM.REPORT (memtype=CATALOG).
NOTE: Deleting USCLIM.USHIGH (memtype=DATA).
NOTE: Deleting USCLIM.USLOW (memtype=DATA).

Previous Page | Next Page | Top of Page