Creating and Managing Indexes in SAS: A Comprehensive Guide

chapter 6 n.w
1 / 17
Embed
Share

Learn how to create and manage indexes in SAS using PROC SQL. Understand the importance of indexes, their benefits in query performance, and how to create simple and composite indexes. Explore examples of creating indexes on specific columns and discover unique index capabilities for data optimization in SAS.

  • SAS Indexing
  • PROC SQL
  • Efficient Querying
  • Composite Index
  • Unique Index

Uploaded on | 7 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Chapter 6 Creating and Managing Indexes Using Proc SQL 1

  2. What is An Index? An index is an auxiliary file that stores the physical location of values for one or more specified columns in a table. An index stores unique values for a specified column(s) in ascending order. An index includes value/identifier pairs that allow you to access a row directly, by value. You cannot create an index on a view. 2

  3. Why Use An Index? When a query is submitted on a table, PROC SQL accesses rows in a table in the order in which they are stored in the table, beginning with the first row and reading all rows in the table. For large tables, it can be time consuming for PROC SQL to read all the rows in a table. 3

  4. Why Use An Index? An index on a table may allow a PROC SQL query to execute more efficiently. We can refer to the LOG to view real time and CPU time (we will learn about STIMER in Chapter 8) for a partial measure of efficiency gains True benchmarking requires restart of SAS session 4

  5. Simple and Composite Indexes Two types of indexes can be created Simple based on one column. The name of the index must be the name of the indexed column. Composite based on two or more columns. The name of the composite index cannot be the name of any existing column or index in the table. 5

  6. Example - Creating A Simple Index Suppose we had a table (meddb) containing all doctors claims for 100,000 patients. If we wanted to create an index on the patient s Social Security Number (ssn), we would use the following code. proc sql; create index ssn on meddb(ssn); quit; 6

  7. Example - Creating A Composite Index If we wanted to create a composite index on the patient s Social Security Number (ssn) and the type of service the patient received (tos), we would use the following code proc sql; create index ssntos on meddb(ssn,tos); quit; 7

  8. Unique Indexes Simple and composite indexes can be defined as unique indexes. Add the word unique before the word index when creating a unique index If a table contains multiple occurrences of the same value in a column, a unique index cannot be defined on that column. 8

  9. Costs of Using an Index Additional CPU time Additional input/output requests may be required Additional memory Additional disk space to store the index file 9

  10. Guidelines for Creating Indexes Keep the number of indexes to a minimum Do not create an index for small tables Do not create an index on a column that has a small number of distinct values (low cardinality) Use indexes for queries that return a small subset of rows (< 15%) 10

  11. Guidelines for Creating Indexes Create an index when the key column occurs in A WHERE clause that contains a comparison operator, CONTAINS operator, or LIKE operator A WHERE clause that contains a SUBSTR or TRIM function 11

  12. Guidelines for Creating Indexes Create an index when the key column occurs in A subquery that returns values to the IN operator A correlated subquery that compares the correlated reference with the key column 12

  13. Guidelines for Creating Indexes Create an index when the key column Occurs in a join in which all columns are indexed for one of the tables in the join Occurs in a join in which the JOIN expression contains an equality (=) operator Has been pre-sorted 13

  14. Describe Table Statement Use to display a CREATE INDEX statement in the SAS log for each index that is defined If no indexes are defined for the specified table, a CREATE INDEX statement will not appear in the SAS log 14

  15. MSGLEVEL = Option To determine if an index is used, specify the SAS system option MSGLEVEL=I. The default for the MSGLEVEL= option is MSGLEVEL=N. This will display notes, warnings, and error messages only. OPTIONS MSGLEVEL=I; 15

  16. IDXWHERE = Option IDXWHERE=YES Tells SAS to choose the best index to process the WHERE expression IDXWHERE=NO Tells SAS to ignore all indexes IDXNAME= index name Tells SAS to use the specified index 16

  17. Dropping Indexes Use the drop index statement to drop(delete) one or more indexes drop index ssn from claims; quit; proc sql; 17

More Related Content