How to Delete Index on SAS dataset

In this article we’ve already described 4 ways to create indexes on SAS dataset with practical examples.

I’m assuming you’ve a SAS dataset which already has indexes defined on it. For any reason you want to delete those indexes on the SAS dataset, this is the article where you learn how to remove indexes. 

How to Delete Index in SAS

Before deleting an index on a sas dataset you should now index details available on that particular dataset so you can use that information to delete it from a dataset.

For demonstration purposes let’s create an index on SAS dataset using one of the 4 methods to create index on SAS dataset.

data work.temp_zipcode (index=(ZIP / unique StateCityZip=(State City ZIP) / unique ));

   set sashelp.ZIPCODE;

run;

Know Index Details:

Use proc contents procedure to get all the details about indexes available on sas dataset. 

proc contents data=work.temp_zipcode; quit;
Index on SAS dataset

There are two ways you can delete indexes from a sas dataset. The first one is using proc dataset and second one is using proc sql.

Two ways to delete Index from a SAS dataset:

  1. Delete Index using PROC SQL
  2. Delete Index using PROC DATASETS

1. Delete Index using PROC SQL

You can also use proc sql to delete indexes from a dataset. The only thing here is you have to list all selected indexes which you want to delete and add them after the DROP INDEX statement.

proc sql;

drop index ZIP on work.temp_zipcode;
drop index StateCityZip on work.temp_zipcode;

quit;

proc contents data=work.temp_zipcode; quit;
delete index on sas dataset using proc SQL

2. Delete Index using PROC DATASETS

Get the index name by running the proc contents query and list them after “INDEX DELETE” statements in proc datasets. You can list any specific index or list all the available indexes which you want to delete it.

proc datasets lib=work;

modify temp_zipcode;

index delete ZIP;

index delete StateCityZip;

run;

proc contents data=work.temp_zipcode; quit;
delete index on sas dataset using proc datasets

Do you want to delete all the indexes available on a sas dataset? 

It’s even better.

You don’t need to mention the index names individually. You just use the _ALL_ option. SAS will delete all the available indexes from a dataset.

proc datasets lib=work;

modify temp_zipcode;

index delete _all_;

run;

proc contents data=work.temp_zipcode; quit;
delete all indexes on sas dataset using proc datasets

FAQ

Can we delete any specific index on SAS dataset?

Yes. You can delete any specific index you want to remove from a SAS dataset. Firstly, get the details about available indexes on your dataset using proc contents procedure and use either proc sql or proc datasets procedure to delete that index.

Can we delete all the indexes available on SAS dataset?

You can delete all the available indexes in one go by listing down all the index names or using _ALL_ keyword with proc datasets procedure. (see method 2: Delete Index using proc sql )