Deleting observations and reclaiming disk space


When an observation is deleted from a non-compressed SAS data file, the observation is marked for deletion, but not physically removed. The space is not reclaimed by the operating system until the data file is recreated through a DATA Step without a MODIFY statement, or PROC COPY or PROC SORT, which creates the data file.

Because of this, a PROC CONTENTS shows a number of deleted observations, but the number of data pages does not shrink.

With compressed data files, the structure is different. When using a MODIFY statement to remove observations, if the REUSE option is set to NO, the entry for that observation remains in the segment table, but the actual observation's data is returned to the available space pool.

When REUSE=YES, in addition to making the observation's space available, the marker is removed from the segment table as well.

When REUSE=YES, you can delete and add new observations within the same DATA Step and new observations use the space made available by the deleted observations.