Repairing Damaged SAS Files

Detecting Damage to SAS Files

The Base SAS engine detects possible damage to SAS data files (including indexes, integrity constraints, and the audit file) and SAS catalogs and provides a means for repairing some of the damage. If one of the following events occurs while you are updating a SAS file, SAS can recover the file and repair some of the damage:
  • A system failure occurs while the data file or catalog is being updated.
  • The disk where the data file (including the index file and audit file) or catalog is stored becomes full before the file is completely written to it.
  • An input/output error occurs while writing to the data file, index file, audit file, or catalog.
When the failure occurs, the observations or records that were not written to the data file or catalog are lost and some of the information about where values are stored is inconsistent. The next time SAS reads the file, it recognizes that the file's contents are damaged and repairs it to the extent possible in accordance with the setting for the DLDMGACTION= data set option or system option, unless the data set is truncated. In this case, use the REPAIR statement to restore the data set.
If damage occurs to the storage device where a data file resides, you can restore the damaged data file, the index, and the audit file from a backup device.
Note: SAS is unable to repair or recover a SAS view (a DATA step view, an SQL view, or a SAS/ACCESS view) or a stored compiled DATA step program. If a SAS file of type VIEW or PROGRAM is damaged, you must recreate it.
Note: If the audit file for a SAS data file becomes damaged, you cannot process the data file until you terminate the audit trail. Then, you can initiate a new audit file or process the data file without one.

Recovering SAS Data Files

To determine the type of action SAS takes when it tries to open a SAS data file that is damaged, set the DLDMGACTION= data set option or system option. That is, when a data file is detected as damaged, SAS automatically responds based on your specification as follows:
DLDMGACTION=FAIL
tells SAS to stop the step without a prompt and issue an error message to the log indicating that the requested file is damaged. This specification gives the application control over the repair decision and provides awareness that a problem occurred.
To recover the damaged data file, you can issue the REPAIR statement in PROC DATASETS, which is documented in Base SAS Procedures Guide.
DLDMGACTION=ABORT
tells SAS to terminate the step, issue an error message to the log indicating that the request file is damaged, and end the SAS session.
DLDMGACTION=REPAIR
tells SAS to automatically repair the file and rebuild indexes, integrity constraints, and the audit file as well. If the repair is successful, a message is issued to the log indicating that the open and repair steps were successful. If the repair is unsuccessful, processing stops without a prompt and an error message is issued to the log indicating the requested file is damaged.
Note: If the data file is large, the time needed to repair it can be long.
DLDMGACTION=NOINDEX
tells SAS to automatically repair the data file, disable the indexes and integrity constraints, delete the index file, update the data file to reflect the disabled indexes and integrity constraints, and limit the data file to be opened only in INPUT mode. A warning is written to the SAS log instructing you to execute the PROC DATASETS REBUILD statement to correct the disabled indexes and integrity constraints and rebuild the index file. For more information, see Recovering Disabled Indexes and Integrity Constraints.
DLDMGACTION=PROMPT
tells SAS to provide the same behavior that exists in Version 6 for both interactive mode and batch mode. For interactive mode, SAS displays a dialog box that asks you to select the FAIL, ABORT, or REPAIR action. For batch mode, the files fail to open.
For a data file, the date and time of the last repair and a count of the total number of repairs is automatically maintained. To display the damage log, use PROC CONTENTS as shown below:
proc contents data="c:\temp\testuser\large";
run;
Output of CONTENTS Procedure
Output of CONTENTS Procedure

Recovering Indexes

In addition to the failures listed earlier, you can damage the indexes for SAS data files by using an operating environment command to delete, copy, or rename a SAS data file, but not its associated index file. The index is repaired similarly to the DLDMGACTION= option as described for SAS data files, or you can use the REPAIR statement in PROC DATASETS to rebuild composite and simple indexes that were damaged.
You cannot use the REPAIR statement to recover indexes that were deleted by one of the following actions:
  • copying a SAS data file by some means other than PROC COPY or PROC DATASETS, for example, using a DATA step
  • using the FORCE option in the SORT procedure to write over the original data file
In the above cases, the index must be rebuilt using the PROC DATASETS INDEX CREATE statement.

Recovering Disabled Indexes and Integrity Constraints

When the DLDMGACTION=NOINDEX data set or system option is used and SAS encounters a damaged data file, SAS does the following:
  • automatically repairs the data file without the indexes and integrity constraints
  • disables the indexes and integrity constraints
  • deletes the index file
  • updates the data file to reflect the disabled indexes and integrity constraints
  • limits the data file to be opened only in INPUT mode
  • writes the following warning to the SAS log:
    WARNING: SAS data file MYLIB.MYFILE.DATA was damaged and has been partially 
    repaired. To complete the repair, execute the DATASETS procedure REBUILD statement.
The data file stays in INPUT mode until the PROC DATASETS REBUILD statement is executed. You use this statement to specify whether you want to restore the indexes and integrity constraints and rebuild the index file or delete the disabled integrity constraints and indexes. For more information, see the REBUILD statement, DATASETS Procedure in Base SAS Procedures Guide.

Recovering Catalogs

To determine the type of action that SAS takes when it tries to open a SAS catalog that is damaged, set the DLDMGACTION= data set option or system option. Then when a catalog is detected as damaged, SAS automatically responds based on your specification.
Note: There are two types of catalog damage:
  • localized damage is caused by a disk condition. This damage results in some data in memory not being flushed to disk. The catalog entries that are currently open for update are marked as damaged. Each damaged entry is checked to determine whether all the records can be read without error.
  • severe damage is caused by a severe I/O error. The entire catalog is marked as damaged.
DLDMGACTION=FAIL
tells SAS to stop the step without a prompt and issue an error message to the log indicating that the requested file is damaged. This specification gives the application control over the repair decision and provides awareness that a problem occurred.
To recover the damaged catalog, you can issue the REPAIR statement in PROC DATASETS, which is documented in the Base SAS Procedures Guide. Note that when you use the REPAIR statement to restore a catalog, you receive a warning for entries that have possible damage. Entries that have been restored might not include updates that were not written to disk before the damage occurred.
DLDMGACTION=ABORT
tells SAS to terminate the step, issue an error message to the log indicating that the requested file is damaged, and end the SAS session.
DLDMGACTION=REPAIR
for localized damage, tells SAS to automatically check the catalog to see which entries are damaged. If there is an error reading an entry, the entry is copied. If an error occurs during the copy process, then the entry is automatically deleted. For severe damage, the entire catalog is copied to a new catalog.
DLDMGACTION=PROMPT
for localized damage, tells SAS to provide the same behavior that exists in SAS 6 for both interactive mode and batch mode. For interactive mode, SAS displays a dialog box that asks you to select the FAIL, ABORT, or REPAIR action. For batch mode, the files fail to open. For severe damage, the entire catalog is copied to a new catalog.
Unlike data files, a damage log is not maintained for a catalog.