data aaa;
input x;
cards;
1
1.1
2.22
3.1415
13.141
110.1
;
run;
data bbb;
set aaa;
y=int(x);
if x=y then z=0;
else z=sum(length(compress(int(x))),1);
run;
得到小数点的位置,但是不太明白,放入宏变量是什么意思。
data _null_;
set bbb;
call execute('%test('||z||')');
run;
是需要这样吗?
看来还没达到楼主要求。再努力一下:
Data bbb;
set aaa;y=scan(x,2, ".");
if y=" " then decimal=0;
else decimal=length(scan(x,2, "."));
drop y;
run;
Decimal 就是数据aaa 中变量x的小数点位数。
Proc sql ;
select max(decimal) into :MaxDecimal
from bbb;
quit;
%put the maximum decimal is %left(&MaxDecimal);
data aaa;
set aaa;
num=length(strip(x))-length(strip(scan(x,1,".")))-1;
if num<0 then num=0;
run;
proc sql noprint;
select max(num) into:num from aaa;
quit;
%put &num.;