SAS:至少有两个小数点的数字



我想用这种方式在SAS中显示数字,最少有两个小数点:

1->1.00

1/2->0.50

1/3->0.3333333333

1/4->0.25

1/5->0.20

这需要一种格式。这怎么可能?提前感谢!

您可以创建依赖于Proc FCMP创建的用户定义函数的自定义格式。

示例:

proc fcmp outlib=work.functions.formats; 
function egad(x) $;
length result $50;
result = putn(x,'best12.');
p = index(result,'.');
if p then do;
if substr(result,p+1,1)=' ' then result=cats(result,'00');
else
if substr(result,p+2,1)=' ' then result=cats(result,'0');
end;
else
result=cats(result,'.00');
return (result);
endsub;
run;
options cmplib=work.functions;
proc format;
value egad (default=12) other=[egad()];

* verify that both the function and format are working; 
data _null_;
x = 1/3;
s = egad(x);
t = put(x,egad.);
put x= s= t=;
run;

最新更新