Summary

Text Summary

Using Indexes

An index is a SAS file that is associated with a data set and that contains information about the location and the values of key variables in the data set. Indexes enable SAS to directly access specific observations rather than having to read all observations sequentially. An index can be simple or composite.

Creating Indexes in the DATA Step

You can create an index at the same time that you create a data set by using the INDEX= option in the DATA statement. Both simple and composite indexes can be unique, if there are no duplicate values for any key variable in the data set. You can create multiple indexes on one data set. You can use the MSGLEVEL= system option to write informational messages to the SAS log that pertain to indexes. Indexes can improve the efficiency of SAS, but there are certain instances where indexes do not improve efficiency and therefore should not be used.

Managing Indexes with PROC DATASETS and PROC SQL

You can use the INDEX CREATE statement or the INDEX DELETE statement in PROC DATASETS to create or delete an index from an existing data set. Using PROC DATASETS to manage indexes uses less system resources than it would to rebuild the data set and update indexes in the DATA step. If you want to delete an index and create an index in the same PROC DATASETS step, you should delete the old index before you create the new index so that SAS can reuse space from the deleted index. You can also use PROC SQL to create or delete an index from an existing data set.

Documenting and Maintaining Indexes

All indexes that are created for a particular data set are stored in one file in the same SAS library as the data set. You can use PROC CONTENTS to print a list of all indexes that exist for a data set, along with other information about the data set. The CONTENTS statement of the PROC DATASETS step can generate the same list of indexes and other information about a data set.
Many of the maintenance tasks that you perform on your data sets affect the index file that is associated with the data set. When you copy a data set with the COPY statement in PROC DATASETS, the index file is reconstructed for you. When you rename a data set or rename a variable with PROC DATASETS, the index file is automatically updated to reflect this change.

Sample Programs

Creating an Index in the DATA Step

options msglevel=i;
data sasuser.sale2000(index=(origin FlightDate=
                      (flightid date)/unique));
   infile 'sale2000.dat';
   input FlightID $7. RouteID $7. Origin $3.
         Dest $3. Cap1st 8. CapBusiness 8.
         CapEcon 8. CapTotal 8. CapCargo 8.
         Date date9. Psgr1st 8./
         PsgrBusiness 8. PsgrEcon 8.
         Rev1st dollar15.2
         RevBusiness dollar15.2
         RevEcon dollar15.2 SaleMon $7.
         CargoWgt 8./ RevCargo dollar15.2;
run;

Managing Indexes with PROC DATASETS

proc datasets library=sasuser nolist;
   modify sale2000;
   index delete origin;
   index create flightid;
   index create Tofrom=(origin dest);
quit;

Managing Indexes with PROC SQL

proc sql;
   create index Tofrom on
          sasuser.sale2000(origin, dest);
   drop index origin from sasuser.sale2000;
quit;
You can also generate reports using the Dictionary.Indexes table
proc sql;
   select *
        from dictionary.indexes
          where libname='SASUSER' and
memname='SALE2000';
   quit;

Points to Remember

  • An index can enable SAS to more efficiently access specific observations of a data set. However, because indexes use system resources, they should be created only on variables that are commonly used to select observations.
  • An index is associated with a data set but is stored as a separate file. You can use PROC DATASETS or PROC CONTENTS to generate a report on a data set's indexes. You can also right-click on a data set in SAS Explorer and select view columns to view a list of the data set's indexes. You should view this information after you have performed maintenance tasks on your data set to ensure that the index file has been maintained.
..................Content has been hidden....................

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