全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1819 5
2010-02-03
data x;
input x y;
z=y>0+x>0;    --------改成z=y>0; 可以
cards;
1 2
0 1
-1 3
;
run;
得不到正确的结果,why??


  data x;
input x y;
z=sum(sign(x) ,sign(y) ); 用符号函数可以解决
cards;
1 2
0 1
. 3
;
run;
二维码

扫码加我 拉你入群

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

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

全部回复
2010-2-3 16:46:22
不明白你想干嘛...
二维码

扫码加我 拉你入群

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

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

2010-2-3 21:54:50
1# lilinzhong

In view of the Order of Evaluation in Compound Expressions in SAS, the expression here z = y>0+x>0 is equivalent to z = (y>0+x)>0, but you were expecting z = (y>0)+(x>0). I think this is where the discrepancy comes from.    I would suggest that you properly using brackets to make the expression more explicit.

JingJu
二维码

扫码加我 拉你入群

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

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

2010-2-4 07:08:11
lilinzhong 发表于 2010-2-3 16:18
data x;
input x y;
z=y>0+x>0;    --------改成z=y>0; 可以
cards;
1 2
0 1
-1 3
;
run;
得不到正确的结果,why??


  data x;
input x y;
z=sum(sign(x) ,sign(y) ); 用符号函数可以解决
cards;
1 2
0 1
. 3
;
run;
Boolean value in SAS has one of only two values, {1, 0}    1=true , 0= false

In the case


z=y>0+x>0;

is the same as z=y>(0+x)>0; accoring to the operation order.
x  y
1 2        2>1>0   {true}    z=1;
0 1        1>0>0   {false}  z=0
-1 3       3>-1>0 {false}  z=0

That is what you see.
二维码

扫码加我 拉你入群

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

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

2010-2-4 07:40:01
3# jingju11

the expression here z = y>0+x>0 is equivalent to z = (y>0+x)>0


Clearly I was wrong. Sorry about that and thanks for the correction. So,

z = y>0+x>0 is equivalent to z = (y>(0+x)>0)

JingJu
二维码

扫码加我 拉你入群

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

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

2010-2-4 09:46:05
谢谢,解决了。果然如此,忽略了这个细节。
二维码

扫码加我 拉你入群

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

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

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群