<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Adding to an Existing Index in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-to-an-Existing-Index/m-p/553308#M153854</link>
    <description>&lt;P&gt;I have a data set such as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 input c1 c2 c3 c4;
 datalines;
 1 3 5 2
 3 5 1 7
 2 6 8 9
 1 2 7 3
 6 1 9 1
 9 1 3 6
 4 1 1 7
 ;
 run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have indexed it as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2 (index=(c1
c2
));
set test;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Suppose I want to index on an additional column at a later time, is there a way to add an index for c3, without deleting or re-indexing the columns c1 and c2? For my actual purposes, re-indexing columns c1 and c2 is very expensive as it is a very large data set. Obviously if you do the below you lose your indexes to 1 and 2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2 (index=(c3
));
set test2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And if you do the following you re-index over all 3 columns (very computationally expensive):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2 (index=(c1
c2
c3
));
set test;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there anyway to get the results of indexing over all 3 columns, without having to redo the indexes on 1 and 2?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Apr 2019 15:21:30 GMT</pubDate>
    <dc:creator>A_SAS_Man</dc:creator>
    <dc:date>2019-04-23T15:21:30Z</dc:date>
    <item>
      <title>Adding to an Existing Index</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-to-an-Existing-Index/m-p/553308#M153854</link>
      <description>&lt;P&gt;I have a data set such as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 input c1 c2 c3 c4;
 datalines;
 1 3 5 2
 3 5 1 7
 2 6 8 9
 1 2 7 3
 6 1 9 1
 9 1 3 6
 4 1 1 7
 ;
 run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have indexed it as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2 (index=(c1
c2
));
set test;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Suppose I want to index on an additional column at a later time, is there a way to add an index for c3, without deleting or re-indexing the columns c1 and c2? For my actual purposes, re-indexing columns c1 and c2 is very expensive as it is a very large data set. Obviously if you do the below you lose your indexes to 1 and 2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2 (index=(c3
));
set test2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And if you do the following you re-index over all 3 columns (very computationally expensive):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2 (index=(c1
c2
c3
));
set test;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there anyway to get the results of indexing over all 3 columns, without having to redo the indexes on 1 and 2?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 15:21:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-to-an-Existing-Index/m-p/553308#M153854</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2019-04-23T15:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: Adding to an Existing Index</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-to-an-Existing-Index/m-p/553316#M153857</link>
      <description>&lt;P&gt;Yes, there are 2 ways in fact - one with&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and another using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot modify an existing index, but you can delete one and add another.&amp;nbsp; Here is the syntax for creating a new, simple index with both approaches:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test(index=(c1 c2));
input c1 c2 c3 c4;
datalines;
1 3 5 2
3 5 1 7
2 6 8 9
1 2 7 3
6 1 9 1
9 1 3 6
4 1 1 7
;
run;
/* add index with proc sql; */
proc sql;
create index c3 on test(c3);

/* add index with proc datasets */
Proc Datasets library = work nolist;
modify test;
index create c4;
quit;

proc sql;
describe table test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The describe statement 'describes' the table (including indexes) in the log, and will show:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table WORK.TEST( bufsize=65536 )

(
c1 num,
c2 num,
c3 num,
c4 num
);
create index c4 on WORK.TEST(c4);
create index c3 on WORK.TEST(c3);
create index c1 on WORK.TEST(c1);
create index c2 on WORK.TEST(c2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 15:36:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-to-an-Existing-Index/m-p/553316#M153857</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2019-04-23T15:36:27Z</dc:date>
    </item>
  </channel>
</rss>

