Reputation: 11
I want to display numbers in SAS this way, with two decimal points minimum:
1 -> 1.00
1/2 -> 0.50
1/3 -> 0.3333333333
1/4 -> 0.25
1/5 -> 0.20
This needs to be a format. How is this possible? Thanks in advance!
Upvotes: 1
Views: 233
Reputation: 27516
You can create a custom format that relies on a user defined function created by Proc FCMP
.
Example:
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;
Upvotes: 1