INDEX
variables
NONE ;
The INDEX statement creates an index for the named variables in the current input SAS data set. An index is created for each variable listed, provided that the variable does not already have an index. Current retrieval is set to the last variable indexed. Subsequent I/O operations such as LIST, READ, FIND, and DELETE can use this index to retrieve observations from the data. The indices are automatically updated when a data set is edited with the APPEND, DELETE, or REPLACE statements. Only one index is in effect at any given time. The SHOW CONTENTS command indicates which index is in use.
For example, the following statements copy the Sasuser.Class
data set and create indexes for the Name
and Sex
variables. Current retrieval is set to use the Sex
variable, as shown in Figure 24.165.
data class; set Sashelp.Class; run;
proc iml; use class; index name sex; list all; close class;
Figure 24.165: Result of Listing Observations of an Indexed Data Set
OBS Name Sex Age Height Weight ------ -------- --- --------- --------- --------- 2 Alice F 13.0000 56.5000 84.0000 3 Barbara F 13.0000 65.3000 98.0000 4 Carol F 14.0000 62.8000 102.5000 7 Jane F 12.0000 59.8000 84.5000 8 Janet F 15.0000 62.5000 112.5000 11 Joyce F 11.0000 51.3000 50.5000 12 Judy F 14.0000 64.3000 90.0000 13 Louise F 12.0000 56.3000 77.0000 14 Mary F 15.0000 66.5000 112.0000 1 Alfred M 14.0000 69.0000 112.5000 5 Henry M 14.0000 63.5000 102.5000 6 James M 12.0000 57.3000 83.0000 9 Jeffrey M 13.0000 62.5000 84.0000 10 John M 12.0000 59.0000 99.5000 15 Philip M 16.0000 72.0000 150.0000 16 Robert M 12.0000 64.8000 128.0000 17 Ronald M 15.0000 67.0000 133.0000 18 Thomas M 11.0000 57.5000 85.0000 19 William M 15.0000 66.5000 112.0000 |
The INDEX NONE statement can be used to set retrieval back to physical order.
When a WHERE clause is being processed, the SAS/IML language automatically determines which index to use, if any. The decision is based on the variables and operators involved in the WHERE clause, and the decision criterion is based on the efficiency of retrieval.