DATASETS Procedure

REBUILD Statement

Specifies whether to restore or delete the disabled indexes and integrity constraints.

Default:Rebuild indexes and integrity constraints
Restriction:The REBUILD statement applies only to data sets created in Version 7 or later

Syntax

Required Argument

SAS-file

specifies a SAS data file that contains the disabled indexes and integrity constraints. You can also use a numbered range list or colon list.

SeeData Set Name Lists in SAS Programmer’s Guide: Essentials.

Optional Arguments

ENCRYPTKEY=key-value

specifies a key value for AES encryption.

RequirementENCRYPTKEY= data set option is required if the data file has AES encryption.

ALTER=alter-password

provides the Alter password for any alter-protected SAS files that are named in the REBUILD statement. You can use the option either in parentheses after the name of each SAS file or after a forward slash.

GENNUM=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. Valid value is integer, which 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). Specifying 0, which is the default, refers to the base version.

MEMTYPE=member-type

restricts processing to one member type.

AliasesMTYPE=
MT=
DefaultIf you do not specify the MEMTYPE= option in the PROC DATASETS statement or in the REBUILD statement, the default is MEMTYPE=ALL.

NOINDEX

specifies to delete the disabled indexes and integrity constraints.

RestrictionThe NOINDEX option cannot be used for data files that contain one or more referential integrity constraints.

Details

When the DLDMGACTION=NOINDEX data set or system option is specified and SAS encounters a damaged data file, SAS does the following:

  • repairs the data file without 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 REBUILD statement completes the repair of a damaged SAS data file by rebuilding or deleting all of the data file's disabled indexes and integrity constraints. The REBUILD statement establishes and uses member-level locking in order to process the new index file and to restore the indexes and integrity constraints.

To rebuild the index file and restore the indexes and integrity constraints, use the following code:

proc datasets library=mylib;
rebuild myfile
/alter=password
 gennum=n
 memtype=mytype;

To delete the disabled indexes and integrity constraints, use the following code:

proc datasets library=mylib;
rebuild myfile /noindex;

After you execute the REBUILD statement, the data file is no longer restricted to INPUT mode.

The REBUILD statement default is to rebuild the indexes and integrity constraints and the index file.

If a data file contains one or more referential integrity constraints and you use the NOINDEX option with the REBUILD statement, the following error message is written to the SAS log:

Error: Unable to rebuild data file MYLIB.MYFILE.DATA using the
              NOINDEX option because the data file contains referential
              constraints. Resubmit the REBUILD statement without the
              NOINDEX option to restore the data file.
Last updated: September 15, 2026