jolterheadmmtt 发表于 2012-9-25 18:21 
嗯嗯,出来结果了,谢谢
可是为什么原来的if 条件不行呢,书上的一段代码就是这么用的,结果却可以运行
...
It is really inefficient to operate on index when one can vectorized an operation. Here is a vectorized one.
PROC IML;
bmi={15,22,27,19,32,17,23,31,20};
status=J(nrow(bmi),1,"unhealthy");
status[loc(bmi>=18.5 & bmi<=20)]="healthy";
print status;
quit;
one can see it is 10 times slower as tested below!!!!!!!!
PROC IML;
*****1)********************;
bmi=j(1e6,1,.);
status=J(nrow(bmi),1,"unhealthy");
call randseed(12345);
call randgen(bmi, 'UNIFORM');
time=time();
status[loc(bmi>=0.4 & bmi<=0.6)]="healthy";
time=time()-time;
print 'time of vectorized' time;
*****2)********************;
bmi=j(1e6,1,.);
status=J(nrow(bmi),1,"unhealthy");
call randseed(12345);
call randgen(bmi, 'UNIFORM');
time=time();
do i=1 to nrow(bmi);
if bmi
>= 0.4 & bmi <= 0.6 then ;
status="healthy";
ELSE status="unhealthy";
end;
time=time()-time;
print 'time of index' time;
quit;