Examples use tables created via 'CREATE TABLE ... LIKE' from an existing table (COUNTRIES), assumed to be available or internally created for the purpose of the example.
1 Code Block
PROC SQL Data
Explanation : This example first creates a new table named `newcountries` using the structure of the `countries` table. Then, it creates a simple index named `area` on the `area` column of the `newcountries` table. A simple index is applied to a single column, and its name must be identical to that of the indexed column.
Copied!
proc sql;
create table newcountries
like countries;
create index area
on newcountries(area);
quit;
1
PROC SQL;
2
create TABLE newcountries
3
like countries;
4
create index area
5
on newcountries(area);
6
QUIT;
2 Code Block
PROC SQL
Explanation : This example creates a composite index named `places` on the `name` and `continent` columns of the `newcountries` table. A composite index applies to two or more columns. The name of the composite index cannot be the same as the name of any of the table's columns.
Copied!
proc sql;
create index places
on newcountries(name, continent);
quit;
1
PROC SQL;
2
create index places
3
on newcountries(name, continent);
4
QUIT;
3 Code Block
PROC SQL
Explanation : This example recreates the `newcountries` table (if it doesn't exist) and then creates a unique composite index named `places` on the `name` and `continent` columns. The use of the `UNIQUE` keyword ensures that each combination of values in the `name` and `continent` columns of the table is unique. Any attempt to modify the table in a way that would result in non-unique index values will be rejected by SAS.
Copied!
proc sql;
create table newcountries
like countries;
create unique index places
on newcountries(name, continent);
quit;
1
PROC SQL;
2
create TABLE newcountries
3
like countries;
4
create unique index places
5
on newcountries(name, continent);
6
QUIT;
4 Code Block
PROC SQL
Explanation : This example drops the index named `places` from the `newcountries` table using the `DROP INDEX` statement. This is useful for freeing up disk space or for adjusting indexing strategies to improve performance.
Copied!
proc sql;
drop index places from newcountries;
quit;
1
2
PROC SQL;
3
drop index places from newcountries;
4
QUIT;
5
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.