<?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 Re: SQL not using index in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59633#M16836</link>
    <description>Agree with Linus.Index is not cared with data' s order.Even if your data has not sorted,index also will promote the processing speed,Index is only logic sorted information not physical. May be you need create a simple index for that special variable.&lt;BR /&gt;
But for your situation - 4.5G file, I do not think it a good idea to use proc sql.&lt;BR /&gt;
You can use Hash Table or proc formate which will use binary search technology to highly speed your proc and save lots of time. You see?&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Tue, 03 May 2011 10:43:25 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-05-03T10:43:25Z</dc:date>
    <item>
      <title>SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59626#M16829</link>
      <description>please can someone point me at some guidance on syntax that persuades PROC SQL to use an index when I only want a few rows and I can provide the keys in an in-list.&lt;BR /&gt;
option msglevel=i ;&lt;BR /&gt;
proc sql _method ; create table bits as &lt;BR /&gt;
select * from &amp;amp;sup_hier where se_no in('9429512452', '9528002678', '9429504095' )&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
(did not use the index on SE_NO)&lt;BR /&gt;
&lt;BR /&gt;
proc sql _method ; create table bit2 as &lt;BR /&gt;
select * from &amp;amp;sup_hier where se_no in('9429512452')&lt;BR /&gt;
union&lt;BR /&gt;
select * from &amp;amp;sup_hier where se_no in('9528002678')&lt;BR /&gt;
union&lt;BR /&gt;
select * from &amp;amp;sup_hier where se_no in('9429504095' )&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
(did use the index)&lt;BR /&gt;
Using the UNION construct must surely be "syntax overkill" here!&lt;BR /&gt;
 &lt;BR /&gt;
all offers welcome&lt;BR /&gt;
 &lt;BR /&gt;
evidence : snip from SASlog running SAS9.2 on aix-64, appears under the sig &lt;BR /&gt;
 &lt;BR /&gt;
peterC&lt;BR /&gt;
[pre]19         option msglevel=i ;&lt;BR /&gt;
20         proc sql _method ;&lt;BR /&gt;
20       !                    create table bits as&lt;BR /&gt;
21         select * from &amp;amp;sup_hier where se_no in('9429512452', '9528002678', '9429504095' )&lt;BR /&gt;
22         ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxsrc( EDWPARK.SE_HR_VOL_ROLL_UP )&lt;BR /&gt;
INFO: Index index1 not used.  Sorting into index order may help.&lt;BR /&gt;
NOTE: Table WORK.BITS created, with 7 rows and 13 columns.&lt;BR /&gt;
&lt;BR /&gt;
23         quit;&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           1:04.23&lt;BR /&gt;
      user cpu time       4.87 seconds&lt;BR /&gt;
      system cpu time     12.24 seconds&lt;BR /&gt;
      &lt;BR /&gt;
&lt;BR /&gt;
24         proc sql _method ;&lt;BR /&gt;
24       !                    create table bit2 as&lt;BR /&gt;
25         select * from &amp;amp;sup_hier where se_no in('9429512452')&lt;BR /&gt;
26         union&lt;BR /&gt;
27         select * from &amp;amp;sup_hier where se_no in('9528002678')&lt;BR /&gt;
28         union&lt;BR /&gt;
29         select * from &amp;amp;sup_hier where se_no in('9429504095' )&lt;BR /&gt;
30         ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxunqs&lt;BR /&gt;
              sqxuall&lt;BR /&gt;
                  sqxuall&lt;BR /&gt;
                      sqxsrc( EDWPARK.SE_HR_VOL_ROLL_UP )&lt;BR /&gt;
                      sqxsrc( EDWPARK.SE_HR_VOL_ROLL_UP )&lt;BR /&gt;
                  sqxsrc( EDWPARK.SE_HR_VOL_ROLL_UP )&lt;BR /&gt;
INFO: Index index1 selected for WHERE clause optimization.&lt;BR /&gt;
INFO: Index index1 selected for WHERE clause optimization.&lt;BR /&gt;
INFO: Index index1 selected for WHERE clause optimization.&lt;BR /&gt;
NOTE: Table WORK.BIT2 created, with 7 rows and 13 columns.&lt;BR /&gt;
&lt;BR /&gt;
31         quit;&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.10 seconds&lt;BR /&gt;
      user cpu time       0.01 seconds&lt;BR /&gt;
      system cpu time     0.00 seconds</description>
      <pubDate>Thu, 28 Apr 2011 15:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59626#M16829</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-04-28T15:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59627#M16830</link>
      <description>Peter,&lt;BR /&gt;
&lt;BR /&gt;
You're findings appear to be consistent with Paul's explanation at:&lt;BR /&gt;
&lt;A href="http://support.sas.com/techsup/technote/ts320.html" target="_blank"&gt;http://support.sas.com/techsup/technote/ts320.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Couldn't you get around the optimizer, though, by including idxname in your from clause?  e.g., from whatever (idxname=nameofindex) ?&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Thu, 28 Apr 2011 16:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59627#M16830</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-28T16:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59628#M16831</link>
      <description>Hi.&lt;BR /&gt;
Peter.It is very interesting , when I use the following code ,Index is used totally.&lt;BR /&gt;
How do you create index? Do you use OR operation to instead it?&lt;BR /&gt;
[pre]&lt;BR /&gt;
data class;&lt;BR /&gt;
 set sashelp.class;&lt;BR /&gt;
run;&lt;BR /&gt;
proc datasets library=work;&lt;BR /&gt;
 modify class;&lt;BR /&gt;
 index create name /unique;&lt;BR /&gt;
quit;&lt;BR /&gt;
options msglevel=i;&lt;BR /&gt;
proc sql _method;&lt;BR /&gt;
create table peter as&lt;BR /&gt;
select *&lt;BR /&gt;
 from class&lt;BR /&gt;
  where name in ('Alice' 'Barbara' 'Judy')&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
42    modify class;&lt;BR /&gt;
43    index create name /unique;&lt;BR /&gt;
NOTE: Simple index Name has been defined.&lt;BR /&gt;
44   quit;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: MODIFY was successful for WORK.CLASS.DATA.&lt;BR /&gt;
NOTE: PROCEDURE DATASETS used (Total process time):&lt;BR /&gt;
      real time           0.03 seconds&lt;BR /&gt;
      cpu time            0.04 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
45   options msglevel=i;&lt;BR /&gt;
46   proc sql _method;&lt;BR /&gt;
47   create table peter as&lt;BR /&gt;
48   select *&lt;BR /&gt;
49    from class&lt;BR /&gt;
50     where name in ('Alice' 'Barbara' 'Judy')&lt;BR /&gt;
51     ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxsrc( WORK.CLASS )&lt;BR /&gt;
INFO: Index Name selected for WHERE clause optimization.&lt;BR /&gt;
NOTE: Table WORK.PETER created, with 3 rows and 5 columns.&lt;BR /&gt;
&lt;BR /&gt;
52   quit;&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.03 seconds&lt;BR /&gt;
      cpu time            0.02 seconds&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
I also notice your index index1 ,is it simple index or composite index? If it were simple index ,it must has the same name with the variable.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Tue, 03 May 2011 03:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59628#M16831</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-03T03:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59629#M16832</link>
      <description>will check (on site) whether my index is unique.&lt;BR /&gt;
Could be because the table filesize is 4.5GB not counting the size of the index.&lt;BR /&gt;
Could be because my data is not in index order. &lt;BR /&gt;
&lt;BR /&gt;
peter</description>
      <pubDate>Tue, 03 May 2011 06:33:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59629#M16832</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-05-03T06:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59630#M16833</link>
      <description>I don't think none of this is the problem.&lt;BR /&gt;
Since your table is quite big, and your result set is small, the index would be used, without regard to data sort order, or uniqueness.&lt;BR /&gt;
&lt;BR /&gt;
The index1 is a composite index, SAS engines does nor allow single indexes with other names than the contributing column.&lt;BR /&gt;
One guess could be that the se_no is not the primary column in the index, which is has to be to being chosen. &lt;BR /&gt;
Looking at the no of distinct values of the contributing columns might also help to understand the situation.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Tue, 03 May 2011 07:36:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59630#M16833</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2011-05-03T07:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59631#M16834</link>
      <description>Linus&lt;BR /&gt;
thank you for looking into this.&lt;BR /&gt;
 &lt;BR /&gt;
here are the index1 attributes[pre]Alphabetic List of Indexes and Attributes &lt;BR /&gt;
              # of &lt;BR /&gt;
             Unique &lt;BR /&gt;
#   Index    Values     Variables &lt;BR /&gt;
1   index1  40932026    SE_NO   SOURCE_SYS_ID [/pre]&lt;BR /&gt;
the column of the in() in the where clause is the first column of the composite index[pre]where se_no in('9429512452', '9528002678', '9429504095' )[/pre]&lt;BR /&gt;
There are 40M unique values&lt;BR /&gt;
and the data are not sorted &lt;BR /&gt;
INFO: Index index1 not used.  Sorting into index order may help.&lt;BR /&gt;
&lt;BR /&gt;
Oddly, that is no handicap for an equality filter, like&lt;BR /&gt;
select * from &amp;amp;sup_hier where se_no in('9429512452')&lt;BR /&gt;
as demo-ed earlier.&lt;BR /&gt;
 &lt;BR /&gt;
appreciate your input&lt;BR /&gt;
Peter</description>
      <pubDate>Tue, 03 May 2011 10:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59631#M16834</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-05-03T10:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59632#M16835</link>
      <description>Well, it happens that I run into Proc SQL issues that makes me frustrated, i.e. as choosing index for joins or not. And many times you just have to accept that Proc SQL have some flaws.&lt;BR /&gt;
Regarding your problem, I have no easy fix tip. I guess that you already have played with IDXWHERE and IDXNAME options?&lt;BR /&gt;
&lt;BR /&gt;
Just for curiosity, what happens if you try an inner join approach? This could trigger a hash join (which is also quite unpredictable...).&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Tue, 03 May 2011 10:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59632#M16835</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2011-05-03T10:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59633#M16836</link>
      <description>Agree with Linus.Index is not cared with data' s order.Even if your data has not sorted,index also will promote the processing speed,Index is only logic sorted information not physical. May be you need create a simple index for that special variable.&lt;BR /&gt;
But for your situation - 4.5G file, I do not think it a good idea to use proc sql.&lt;BR /&gt;
You can use Hash Table or proc formate which will use binary search technology to highly speed your proc and save lots of time. You see?&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 03 May 2011 10:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59633#M16836</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-03T10:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59634#M16837</link>
      <description>Creating a simple index might help, but I think a composite index should work fine given the information in this thread.&lt;BR /&gt;
And I can't see any reason this is not a SQL type of query, unless there is a special flaw in SAS implementation of SQL in this particular scenario. SQL works fine for must "simple" queries. &lt;BR /&gt;
If I'm not mistaken, the WHERE-clause optimizer shares it's logic with the data step and other Procs.&lt;BR /&gt;
&lt;BR /&gt;
What happens if you use a corresponding data step?&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Tue, 03 May 2011 10:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59634#M16837</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2011-05-03T10:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59635#M16838</link>
      <description>Yes.Linus.&lt;BR /&gt;
What you said is all right. However,SQL is not really suitable for very large table like this.&lt;BR /&gt;
SQL will very slowly or collapse your OS when table is very large table.So It is a advantage of SAS to process large table,SAS offer lots of tools to query data Such as Hash Table ,proc format ..... these are very efficient, when you have a large table need to process.That is the reason why I love SAS .&lt;BR /&gt;
&lt;BR /&gt;
I have to leave now.&lt;BR /&gt;
Have a good Day! Linus.&lt;BR /&gt;
:-)&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 03 May 2011 11:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59635#M16838</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-03T11:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59636#M16839</link>
      <description>see later

lack of checking before posting!!! better version later   &lt;BR /&gt;
Message was edited by: Peter.C</description>
      <pubDate>Tue, 03 May 2011 11:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59636#M16839</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-05-03T11:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59637#M16840</link>
      <description>"curiosity killed the ..."[pre]20         data wanted ; * build in-list as inner join;&lt;BR /&gt;
21           do want= '9429512452', '9528002678', '9429504095' ;&lt;BR /&gt;
22         	output ;&lt;BR /&gt;
23           end;&lt;BR /&gt;
24         run ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The data set WORK.WANTED has 3 observations and 1 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
      &lt;BR /&gt;
&lt;BR /&gt;
25         proc sql _method  ;&lt;BR /&gt;
25       !                     create table bitsJ as&lt;BR /&gt;
26         select * from &amp;amp;sup_hier join  wanted on se_no= want ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxjhsh &lt;B&gt;  ========= NOTICE HASH JOIN&lt;/B&gt;&lt;BR /&gt;
              sqxsrc( EDWPARK.SE_HR_VOL_ROLL_UP )&lt;BR /&gt;
              sqxsrc( WORK.WANTED )&lt;B&gt;&lt;BR /&gt;
INFO: Index index1 not used.  Sorting into index order may help.&lt;/B&gt;&lt;BR /&gt;
NOTE: Table WORK.BITSJ created, with 7 rows and 14 columns.&lt;BR /&gt;
&lt;BR /&gt;
27         *where se_no in('9429512452', '9528002678', '9429504095' )&lt;BR /&gt;
28         ;&lt;BR /&gt;
29          create table bitsJ as select * from &amp;amp;sup_hier(idxwhere=yes) join  wanted on se_no= want ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxjhsh  &lt;B&gt;  ========= STILL A HASH JOIN&lt;/B&gt;&lt;BR /&gt;
              sqxsrc( EDWPARK.SE_HR_VOL_ROLL_UP )&lt;BR /&gt;
              sqxsrc( WORK.WANTED )&lt;B&gt;&lt;BR /&gt;
INFO: Data set option (IDXWHERE=YES)forced an index to be used rather than a sequential pass for where-clause processing.&lt;BR /&gt;
INFO: Index index1 selected for WHERE clause optimization.&lt;/B&gt;&lt;BR /&gt;
NOTE: Table WORK.BITSJ created, with 7 rows and 14 columns. [/pre]&lt;BR /&gt;
Although here, I can force the use of the index with the IDXWHERE=YES, it would probably cause an ERROR: if the index was not present. &lt;BR /&gt;
The idea of SQL is to optimise for us, what-ever the conditions, so I cannot always use the IDXWHERE=YES option. &lt;BR /&gt;
 &lt;BR /&gt;
I remain very surprised that an "in-list" excludes the use of an index, even at data sizes like this!&lt;BR /&gt;
 &lt;BR /&gt;
peter</description>
      <pubDate>Tue, 03 May 2011 11:33:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59637#M16840</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-05-03T11:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59638#M16841</link>
      <description>Peter,&lt;BR /&gt;
&lt;BR /&gt;
You never mentioned whether you tried the idxname option.  I can't test it at the moment but, according to the documentation: "Because the index SAS selects might not always provide the best optimization, you can direct SAS to use one of the candidate indexes by specifying the IDXNAME= data set option. If you specify an index that SAS does not identify as a candidate index, then IDXNAME= does not process the request. That is, IDXNAME= does not allow you to specify an index that would produce incorrect results."&lt;BR /&gt;
&lt;BR /&gt;
I don't know if that results in an error or simply overrides the option if the index doesn't exist.&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Tue, 03 May 2011 12:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59638#M16841</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-05-03T12:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59639#M16842</link>
      <description>Ksharp&lt;BR /&gt;
 &lt;BR /&gt;
thank you for taking a look&lt;BR /&gt;
 &lt;BR /&gt;
I adapted your example until it produces similar behaviour to my experience with 4.5GB[pre]19         data class;&lt;BR /&gt;
20          set sashelp.class;&lt;BR /&gt;
21          do until( rap &amp;gt; 99999 );&lt;BR /&gt;
22           rap = 100000* ranuni(1) ;&lt;BR /&gt;
23           nam1= put( rap,z1.)!!name ;[/pre]* I want a large table but almost unique rows ;[pre]24           output ;&lt;BR /&gt;
25          end;&lt;BR /&gt;
26         run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
NOTE: The data set WORK.CLASS has 1260317 observations and 7 variables.&lt;BR /&gt;
NOTE: At least one W.D format was too small for the number to be printed. The decimal may be shifted by the "BEST" format.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           3.77 seconds&lt;BR /&gt;
      cpu time            0.67 seconds&lt;BR /&gt;
      &lt;BR /&gt;
&lt;BR /&gt;
27         proc sort out= classI( index=( key=( nam1 rap  ))) ;[/pre] * my shortcut for building a composite index on data ordered by something else;[pre]28         by weight ;&lt;BR /&gt;
29         run ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 1260317 observations read from the data set WORK.CLASS.&lt;BR /&gt;
NOTE: SAS threaded sort was used.&lt;BR /&gt;
NOTE: The data set WORK.CLASSI has 1260317 observations and 7 variables.&lt;BR /&gt;
INFO: Multiple concurrent threads will be used to create the index.&lt;BR /&gt;
NOTE: Composite index key has been defined.&lt;BR /&gt;
NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;
      real time           4.55 seconds&lt;BR /&gt;
      cpu time            3.11 seconds&lt;BR /&gt;
      &lt;BR /&gt;
&lt;BR /&gt;
30         proc contents varnum;&lt;BR /&gt;
31         run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: PROCEDURE CONTENTS used (Total process time):&lt;BR /&gt;
      real time           0.04 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
      &lt;BR /&gt;
&lt;BR /&gt;
32         options msglevel=i;&lt;BR /&gt;
33         proc sql _method stimer ;&lt;BR /&gt;
NOTE: SQL Statement used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
      &lt;BR /&gt;
34         create table Kpeter as select * from classI(idxwhere=yes) where nam1 in ('1Alice' '1Barbara' '1Judy') ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxsrc( WORK.CLASSI )&lt;BR /&gt;
INFO: Data set option (IDXWHERE=YES)forced an index to be used rather than a sequential pass for where-clause processing.&lt;BR /&gt;
INFO: Index key selected for WHERE clause optimization.&lt;BR /&gt;
NOTE: Table WORK.KPETER created, with 5 rows and 7 columns.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL Statement used (Total process time):&lt;BR /&gt;
      real time           0.02 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
      &lt;BR /&gt;
35         create table Kpeter as select * from class&lt;BR /&gt;
I               where nam1 in ('1Alice' '1Barbara' '1Judy') ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxsrc( WORK.CLASSI )&lt;BR /&gt;
INFO: Index key not used.  Sorting into index order may help.&lt;BR /&gt;
NOTE: Table WORK.KPETER created, with 5 rows and 7 columns.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL Statement used (Total process time):&lt;BR /&gt;
      real time           0.58 seconds&lt;BR /&gt;
      cpu time            0.36 seconds&lt;BR /&gt;
      &lt;BR /&gt;
36         quit;&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):[/pre]Without forcing use of the index, the query takes half | one second. With IDXWHERE=YES, the query time was 1 | 2 (cpu | elapse) hundredths of a second.&lt;BR /&gt;
 &lt;BR /&gt;
If you wish to adapt the test, the clean code follows&lt;BR /&gt;
  &lt;BR /&gt;
regards&lt;BR /&gt;
peterC&lt;BR /&gt;
&lt;BR /&gt;
data class;&lt;BR /&gt;
 set sashelp.class ;&lt;BR /&gt;
 do until( rap &amp;gt; 99999 ) ;&lt;BR /&gt;
  rap = 100000* ranuni(1) ;&lt;BR /&gt;
  nam1= put( rap,z1.)!!name ;&lt;BR /&gt;
  output ;&lt;BR /&gt;
 end ;&lt;BR /&gt;
run ;&lt;BR /&gt;
proc sort out= classI( index=( key=( nam1 rap  ))) ;&lt;BR /&gt;
by weight ;&lt;BR /&gt;
run ;&lt;BR /&gt;
proc contents varnum ;&lt;BR /&gt;
run;&lt;BR /&gt;
options msglevel=i;&lt;BR /&gt;
proc sql _method stimer ;&lt;BR /&gt;
create table Kpeter as select * from classI(idxwhere=yes) where nam1 in ('1Alice' '1Barbara' '1Judy') ;&lt;BR /&gt;
create table Kpeter as select * from classI               where nam1 in ('1Alice' '1Barbara' '1Judy') ;&lt;BR /&gt;
quit ;</description>
      <pubDate>Tue, 03 May 2011 13:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59639#M16842</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-05-03T13:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59640#M16843</link>
      <description>Peter.&lt;BR /&gt;
You are welcome.&lt;BR /&gt;
It looks like composite index does not work for your situation,Only simple index can do. I also learned it one more time.&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 04 May 2011 01:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59640#M16843</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-04T01:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59641#M16844</link>
      <description>Ksharp&lt;BR /&gt;
it is not because the index is composite.&lt;BR /&gt;
A simple index is also rejected - [pre]517  data class;&lt;BR /&gt;
518  set sashelp.class ;&lt;BR /&gt;
519  do until( rap &amp;gt;  99999 ) ;&lt;BR /&gt;
520            rap = 100000 * ranuni(1) ;&lt;BR /&gt;
521  nam1= put( rap,z1.)!!name ;&lt;BR /&gt;
522  output ;&lt;BR /&gt;
523  end ;&lt;BR /&gt;
524  run ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
NOTE: The data set WORK.CLASS has 1260317 observations and 7 variables.&lt;BR /&gt;
NOTE: At least one W.D format was too small for the number to be printed. The decimal may&lt;BR /&gt;
      be shifted by the "BEST" format.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.65 seconds&lt;BR /&gt;
      cpu time            0.65 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
525  proc sort out= classI( index=(nam1 )) ;&lt;BR /&gt;
526  by weight ;&lt;BR /&gt;
527  run ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 1260317 observations read from the data set WORK.CLASS.&lt;BR /&gt;
NOTE: SAS threaded sort was used.&lt;BR /&gt;
NOTE: The data set WORK.CLASSI has 1260317 observations and 7 variables.&lt;BR /&gt;
INFO: Multiple concurrent threads will be used to create the index.&lt;BR /&gt;
NOTE: Simple index nam1 has been defined.&lt;BR /&gt;
NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;
      real time           1.92 seconds&lt;BR /&gt;
      cpu time            2.48 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
528  proc sql _method stimer ;&lt;BR /&gt;
NOTE: SQL Statement used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
529  create table Kpeter as select * from classI(idxwhere=yes) where nam1 in('1Alice'&lt;BR /&gt;
529! '1Barbara' '1Judy') ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxsrc( WORK.CLASSI )&lt;BR /&gt;
INFO: Data set option (IDXWHERE=YES)forced an index to be used rather than a sequential&lt;BR /&gt;
pass for where-clause processing.&lt;BR /&gt;
INFO: Index nam1 selected for WHERE clause optimization.&lt;BR /&gt;
NOTE: Table WORK.KPETER created, with 5 rows and 7 columns.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL Statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
530  create table Kpeter as select * from classI where nam1 in ('1Alice' '1Barbara'&lt;BR /&gt;
530! '1Judy') ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxsrc( WORK.CLASSI )&lt;BR /&gt;
INFO: Index nam1 not used.  Sorting into index order may help.&lt;BR /&gt;
NOTE: Table WORK.KPETER created, with 5 rows and 7 columns.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL Statement used (Total process time):&lt;BR /&gt;
      real time           0.16 seconds&lt;BR /&gt;
      cpu time            0.14 seconds[/pre]&lt;BR /&gt;
So, I think it must be something to do with  file- or index-size  for data not sorted in index order.&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Wed, 04 May 2011 06:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59641#M16844</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-05-04T06:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: SQL not using index</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59642#M16845</link>
      <description>Hey.Peter.&lt;BR /&gt;
I found it very interesting.Obviously value of your nam1 prevent to use index.&lt;BR /&gt;
When I open your class table,I found a * before name,that is not legal.So I change your code a little.So the index is worked ,whether it is simple or composite index, and Linus might be correct. &lt;BR /&gt;
So this remind us to use index after checking data which used to make index.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data class;&lt;BR /&gt;
set sashelp.class ;&lt;BR /&gt;
rapp=0;&lt;BR /&gt;
do until( rapp &amp;gt; 9999 ) ;&lt;BR /&gt;
rapp+1;&lt;BR /&gt;
rap = floor(10* ranuni(1) );&lt;BR /&gt;
namee= cats(put(rap,$1.),name) ;&lt;BR /&gt;
output ;&lt;BR /&gt;
end ;&lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc datasets library=work;&lt;BR /&gt;
 modify class;&lt;BR /&gt;
 index create namee  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
options msglevel=i;&lt;BR /&gt;
proc sql _method stimer ;&lt;BR /&gt;
create table Kpeter as select * from class(idxwhere=yes) where namee in ('1Alice' '1Barbara' '1Judy') ;&lt;BR /&gt;
create table Kpeter as select * from class where namee in ('1Alice' '1Barbara' '1Judy') ;&lt;BR /&gt;
quit ; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
403   modify class;&lt;BR /&gt;
404   index create namee  ;&lt;BR /&gt;
NOTE: Simple index namee has been defined.&lt;BR /&gt;
405  quit;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: MODIFY was successful for WORK.CLASS.DATA.&lt;BR /&gt;
NOTE: PROCEDURE DATASETS used (Total process time):&lt;BR /&gt;
      real time           0.69 seconds&lt;BR /&gt;
      cpu time            0.63 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
406&lt;BR /&gt;
407  options msglevel=i;&lt;BR /&gt;
408  proc sql _method stimer ;&lt;BR /&gt;
NOTE: SQL Statement used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
409  create table Kpeter as select * from class(idxwhere=yes) where namee in ('1Alice' '1Barbara'&lt;BR /&gt;
409! '1Judy') ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxsrc( WORK.CLASS )&lt;BR /&gt;
INFO: Data set option (IDXWHERE=YES)forced an index to be used rather than a sequential pass for&lt;BR /&gt;
where-clause processing.&lt;BR /&gt;
INFO: Index namee selected for WHERE clause optimization.&lt;BR /&gt;
NOTE: Table WORK.KPETER created, with 2969 rows and 8 columns.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL Statement used (Total process time):&lt;BR /&gt;
      real time           0.02 seconds&lt;BR /&gt;
      cpu time            0.03 seconds&lt;BR /&gt;
&lt;BR /&gt;
410  create table Kpeter as select * from class where namee in ('1Alice' '1Barbara' '1Judy') ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL execution methods chosen are:&lt;BR /&gt;
&lt;BR /&gt;
      sqxcrta&lt;BR /&gt;
          sqxsrc( WORK.CLASS )&lt;BR /&gt;
INFO: Index namee selected for WHERE clause optimization.&lt;BR /&gt;
NOTE: Table WORK.KPETER created, with 2969 rows and 8 columns.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SQL Statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.02 seconds&lt;BR /&gt;
&lt;BR /&gt;
411  quit ;&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 04 May 2011 08:28:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-not-using-index/m-p/59642#M16845</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-04T08:28:58Z</dc:date>
    </item>
  </channel>
</rss>

