m******m 发帖数: 445 | 1 %let thres_intp_l=%str(-0.2);
%let intercept=%str(-0.3);
%macro test2;
%if &intercept le &thres_intp_l
%then %put 1;
%else %put 0;
%mend test2;
SAS will output 0 for above. If change to -2 and -3 (integer), the
comparison is correct. How can I get the correct comparison with floating
number?
Thanks! |
n******e 发帖数: 53 | 2 try
%if %SYSEVALF(&intercept) le %SYSEVALF(&thres_intp_l) |
k*******a 发帖数: 772 | 3 can also try
%if %sysevalf(&intercept le &thres_intp_l) |
m******m 发帖数: 445 | 4 have u ever tried this?
I did it but failed. didn't mention in my original post
【在 n******e 的大作中提到】 : try : %if %SYSEVALF(&intercept) le %SYSEVALF(&thres_intp_l)
|
D******n 发帖数: 2836 | 5 try this
%if %sysevalf(&a>&b,boolean)>0 %then .....
this one is tested.
baozi pls.
【在 m******m 的大作中提到】 : have u ever tried this? : I did it but failed. didn't mention in my original post
|
a******n 发帖数: 11246 | 6 其实就是要把字符型的-0.2变为数值型,但我不知道用什么函数。
只会用这个傻x方法解决:(
%if %sysevalf(&intercept+1) le %sysevalf(&thres+1)
【在 m******m 的大作中提到】 : %let thres_intp_l=%str(-0.2); : %let intercept=%str(-0.3); : %macro test2; : %if &intercept le &thres_intp_l : %then %put 1; : %else %put 0; : %mend test2; : SAS will output 0 for above. If change to -2 and -3 (integer), the : comparison is correct. How can I get the correct comparison with floating : number?
|
m******m 发帖数: 445 | 7 thanks!
【在 k*******a 的大作中提到】 : can also try : %if %sysevalf(&intercept le &thres_intp_l)
|
m******m 发帖数: 445 | 8 thanks!
【在 D******n 的大作中提到】 : try this : %if %sysevalf(&a>&b,boolean)>0 %then ..... : this one is tested. : baozi pls.
|
m******m 发帖数: 445 | 9 thanks!
【在 a******n 的大作中提到】 : 其实就是要把字符型的-0.2变为数值型,但我不知道用什么函数。 : 只会用这个傻x方法解决:( : %if %sysevalf(&intercept+1) le %sysevalf(&thres+1)
|
l***a 发帖数: 12410 | 10 +0 中不?
【在 a******n 的大作中提到】 : 其实就是要把字符型的-0.2变为数值型,但我不知道用什么函数。 : 只会用这个傻x方法解决:( : %if %sysevalf(&intercept+1) le %sysevalf(&thres+1)
|
w*****5 发帖数: 515 | 11 晚上看了一点书,分析并总结一下。。不对的地方请大牛指出。
1)%if 其实调用了%eval()来判断表达式
2)%if &intercept le &thres_intp_l相当于%eval( &intercept le &thres_intp_l)
,这个不会出错,因为两个都是字符型,不会自动转换,但是比较结果可能不对。
3)%sysevalf(&intercept le &thres_intp_l)可以得出正确结果,因为%sysevalf(
expression)的结果是1或者0,因此%eval(1)=1, %eval(0)=0
4) 另外3个答案:
%if %sysevalf(&intercept+1) le %sysevalf(&thres+1) 对
%if %sysevalf(&intercept+0) le %sysevalf(&thres+0) 出错
%if %sysevalf(&intercept) le %sysevalf(&thres) 出错
这个比较有意思。因为%if()其实是调用了%eval()
因此,从结果中可以看出,%eval(a》b).如果 a和b是float.
那么如果a,b是正数,结果正确。如果a,b是负数,出错。。
比如把两个数据改成-1.2和-1.3则
%if %sysevalf(&intercept+1) le %sysevalf(&thres+1) 也出错。
这个就不知道为什么了。谁解答一下。
不过,看来,%sysevalf(&intercept le &thres_intp_l)是最好的。 |