标题: if-then和else if-then的区别 [打印本页] 作者: shiyiming 时间: 2012-3-5 11:41 标题: if-then和else if-then的区别 data a;
input jobcode $;
datalines;
actor1
actor2
actor3
data b;
set a ;
if jobcode in ('actor1','actor2') then joblevel='beginner';
if jobcode='actor3' then joblevel='advanced';
else joblevel='unknow';
run;
那在这一段代码中,第二个条件判断如果改为else if 结果就会不一样,这是为什么呢?if和有else if
什么分别作者: shiyiming 时间: 2012-3-5 13:19 标题: Re: if-then和else if-then的区别 if 是完全判断逻辑,else if 是在前面If条件不满足情况下的进一步判断,所以在你这个case里
在第二个If判断时,对于'actor1','actor2,并不会考虑前面的判断结果,统一认为不是'actor3'而赋值'Unknown'.作者: shiyiming 时间: 2012-3-6 09:49 标题: Re: if-then和else if-then的区别 分析的太到位了,我明白了。我看过下面的一个英文解释,但就不怎么看得懂,也把它写出来吧!最后谢谢您了!!!
The DATA step will continue to process those observations that satisfy the conditon in the first IF statement Althouth
jobcode might be set to beginner for one or more observations.the condition on the second IF statement will evaluate
as false,and the ELSE statement will execute and overwrite the value of jobcode as unknow.