楼主: 木颜夕
1433 1

有关index 使用条件的问题 [推广有奖]

  • 0关注
  • 3粉丝

硕士生

27%

还不是VIP/贵宾

-

威望
0
论坛币
1648 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
2867 点
帖子
79
精华
0
在线时间
141 小时
注册时间
2012-8-13
最后登录
2016-12-26

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
1.Suppose that the Sasuser.Revenue data set has a simple index named FlightID.
For which of the following programs will the index be used?
a proc print data=sasuser.revenue;
where flightid ne ’IA11200’;
run;
b data someflights;
set sasuser.revenue;
where flightid > ’IA11200’;
run;
c data someflights;
set sasuser.revenue;
if flightid > ’IA11200’;
run;
d proc print data=sasuser.revenue;
where origin=’RDU’ or flightid=’IA03400’;
run;
答案为b,不明白。

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Index IND following programs Revenue following programs simple origin where

沙发
linusx 发表于 2014-2-14 08:30:55 |只看作者 |坛友微信交流群
>> Correct answer:   b
>>
>> Explanation - An index can improve the efficiency with which
>> SAS is able to access certain observations in a data set.
>> However, an index is not always useful. SAS will not use an
>> index to process subsetting IF statements, or other
>> statements that SAS determines might be more efficiently
>> processed without an index.
>>
>Hari, well that is just one of literally thousands of good reasons that
>you should just drop everything and order my SAS Index book right now.
>As a matter of fact, do not finish reading this posting--go and order
>the book--I will be waiting for you right here with the rest of the
>message.  Go on, you know that you want to!
>
>...okay, ordered it?  Then, read on.  (If not, then delete this message,
>because I do not want you to get the following information for free).
>
>So, here is how I would think about the choices:
>
>a. The NE operator would likely qualify too many observations in a large
>SAS data set with a normal distribution of flightid's.  SAS indexes are
>built to qualify and return a subset of observations--the smaller, the
>better.  So, the NE operator is not one of the constructs that triggers
>SAS's use of indexes.
>
>b. We have a winner here, folks!  Okay index, start walking!


Here's a contrived example where the heuristics don't work out and the
"winner" is actually a loser.


   data with_index(index=(i) ) without_index;
   do i = 1 to 1e7; output; end;
   run;


   data subset;
   set without_index;
   where I > 2;
   run;


   data subset;
   set with_index;
   where I > 2;
   run;


On my machine the step which uses the index takes twice as much time as the
one which does not.


>
>C. You are correct; IF statements are not optimized by SAS indexes; not
>ever; no way, now how!


That's because indexes are used in reading data and subsetting IF statements
have to do with flow of control in the DATA step, an utterly different part
of processing.


>
>D. The OR condition is not on a single variable, but on two different
>ones, so SAS will not consider using an index.


That's because every observation has to be examined anyway to see if the
value of ORIGIN satisfies the WHERE condition.


What would happen if there were an index on ORIGIN in addition to the one on
FlightID? Would SAS then use the two indexes together in order to pull the
correct subset?


> If it were a string of
>OR statements with the same variable being tested on each OR (and an
>index were involved), SAS would consider using the relevant index.
>
>Now that my SAS Index book is headed your way, I can point you at
>Chapter 10: Using Indexes with a WHERE Expression, pages 134 - 136,
>Rules for SAS Using a Simple Index.
>
>Hari, best of luck to you on the final grade for your SAS exam!
>
>
>I hope that this suggestion proves helpful now, and in the future!
>
>Of course, all of these opinions and insights are my own, and do not
>reflect those of my organization or my associates. All SAS code and/or
>methodologies specified in this posting are for illustrative purposes
>only and no warranty is stated or implied as to their accuracy or
>applicability. People deciding to use information in this posting do so
>at their own risk.
>
已有 1 人评分论坛币 收起 理由
admin_kefu + 100 热心帮助其他会员

总评分: 论坛币 + 100   查看全部评分

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 19:19