Or this if you want to ensure the display of all digits (see report lines 4 and 14).
data VALUES;
infile cards truncover;
input VAL 32.;
cards;
-2981248.8
2981248.8
1248.764
248.076403
48.76403
8.76403
0.76403
0.076403
0.0076403
0.00076403
0.000076403
0.000076403871
-0.000076403
-0.000076403
1
;
proc fcmp outlib=WORK.FUNCS.TEST;
function sigdig(VAL, SIG, FMT $) $32;
%* Input validation to be added;
length E F $32;
E = putn(VAL, cats('E', SIG+6, '.'));
if upcase(FMT)='E' then return(strip(E));
else do;
F = cat(input(E, 32.));
L = length(F);
if L < SIG then F = cats(F,'.',repeat('0',SIG-L-1));
return(strip(F));
end;
endsub;
run;
options cmplib=WORK.FUNCS;
data FCT;
set VALUES;
NUM1 = sigdig(VAL, 4, 'S');
NUM2 = sigdig(VAL, 4, 'E');
run;
Obs.
VAL
NUM1
NUM2
1
-2981248.8
-2981000
-2.981E+06
2
2981248.8
2981000
2.981E+06
3
1248.764
1249
1.249E+03
4
248.0076403
248.0
2.480E+02
5
48.76403
48.76
4.876E+01
6
8.76403
8.764
8.764E+00
7
0.76403
0.764
7.640E-01
8
0.076403
0.0764
7.640E-02
9
0.0076403
0.00764
7.640E-03
10
0.00076403
0.000764
7.640E-04
11
0.000076403
0.0000764
7.640E-05
12
0.000076403871
0.0000764
7.640E-05
13
-0.000076403
-0.0000764
-7.640E-05
14
1
1.000
1.000E+00
... View more