Managing Indexes with PROC DATASETS

Overview

You have seen how to create an index at the same time that you create a data set. You can also create an index on an existing data set or delete an index from a data set. One way to accomplish either of these tasks is to rebuild the data set. However, rebuilding the data set is not the most efficient method for managing indexes.
You can use the DATASETS procedure to manage indexes on an existing data set. This uses fewer resources than rebuilding the data set. You use the MODIFY statement with the INDEX CREATE statement to create indexes on a data set. You use the MODIFY statement with the INDEX DELETE statement to delete indexes from a data set. You can also use the INDEX CREATE statement and the INDEX DELETE statement in the same step.
General form, PROC DATASETS to create and delete an index:
PROC DATASETS LIBRARY= libref <NOLIST>;
MODIFY SAS-data-set-name;
INDEX DELETE index-name;
INDEX CREATE index-specification;
QUIT;
Here is an explanation of the syntax:
libref
points to the SAS library that contains SAS-data-set-name.
NOLIST
option suppresses the printing of the directory of SAS files in the SAS log and as ODS output.
index-name
is the name of an existing index to be deleted.
index-specification
for a simple index is the name of the key variable.
index-specification
for a composite index is index-name=(variable-1...variable-n).
The INDEX CREATE statement in PROC DATASETS cannot be used if the index to be created already exists. In this case, you must delete the existing index of the same name, and then create the new index.
Tip
PROC DATASETS executes statements in order. Therefore, if you delete and create indexes in the same step, you should delete the old indexes first so that the newly created indexes can reuse the space that the deleted indexes had occupied.

Example

The following example creates an index named Origin on the Sasuser.Sale2000 data set. Origin is a simple index that is based on the key variable Origin.
proc datasets library=sasuser nolist;
   modify sale2000;
   index create origin;
quit;
The following example first deletes the Origin index from the Sasuser.Sale2000 data set, and creates two new indexes on the Sasuser.Sale2000 data set. FlightID is a simple index that is based on the values of the key variable FlightID. Fromto is a composite index that is based on the concatenated values of the key variables Origin and Dest.
proc datasets library=sasuser nolist;
   modify sale2000;
   index delete origin;
   index create flightid;
   index create Fromto=(origin dest);
quit;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.115.154