Index
When to use index:
1: yield faster access to small subsets of obs for WHERE processing
2: return obs in sorted order for BY processing
3: perform table lookup operations
4: join obs
5: modify obs
Simple index: (index=(myindex)) or (index=(lastname firstname))
Composite index: (index=(comp_index=(lastname firstname)))
Pcoc datasets library=libref;
Modify sas_data_set;
Index delete index_name;
Index create index_specification;
Quit;
Proc sql;
Create index index_name on table_name;
Drop index index_name from table_name;
Quit;
Task | Effect |
Add observation(s) to data set | Value/identifier pairs are added to index(es). |
Delete observation(s) from data set | Value/identifier pairs are deleted from index(es). |
Update observation(s) in data set | Value/identifier pairs are updated in index(es). |
Delete data set | The index file is deleted. |
Rebuild data set with DATA step | The index file is deleted. |
Sort the data in place with the FORCE option in PROC SORT | The index file is deleted. |
Use PROC DATASETS to copy, rename(change) datasets, rename variables
DATA SAS-data-file-name (INDEX=
(index-specification-1</UNIQUE><...index-specification-n</UNIQUE>>));
SET SAS-data-set-name ;
RUN;
PROC DATASETS LIBRARY=libref ;
MODIFY SAS-data-set-name;
INDEX DELETE index-name ;
INDEX CREATE index-specification;
QUIT;
PROC SQL;
CREATE INDEX index-name
ON table-name(column-name-1<...,column-name-n>);
DROP INDEX index-name FROM table-name ;
QUIT;
PROC CONTENTS DATA=SAS-data-set-name;
RUN;
PROC DATASETS <LIBRARY=libref> ;
CONTENTS DATA=SAS-data-set-name;
QUIT;
PROC DATASETS LIBRARY=old-libref ;
COPY OUT=new-libref;
SELECT SAS-data-set-name;
QUIT;
PROC COPY OUT=new-libref IN=old-libref ;
SELECT SAS-data-set-name(s);
RUN;
QUIT;
PROC DATASETS LIBRARY=libref ;
CHANGE old-data-set-name = new-data-set-name;
QUIT;
PROC DATASETS LIBRARY=libref ;
MODIFY SAS-data-set-name;
RENAME old-var-name-1 = new-var-name-1 ;
<...old-var-name-n = new-var-name-n> ;
QUIT;
No comments:
Post a Comment