Sample 24728: Round a numeric variable to 3 significant digits
Use the ABS, LOG10 and INT functions to determine the
appropriate power to use in the ROUND function in order
to round a numeric to 3 significant digits.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
data one;
input x;
if int(x) ne 0 then do;
_3sigdigit=round(x,10**(int(log10(abs(x)))-2));
end;
else do;
_3sigdigit=round(x,10**(-1*(abs(int(log10(abs(x))))+3)));
end;
datalines;
0.00001616
0.0051368
35.479
3149.0865
;
proc print;
format x _3sigdigit 15.8;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Obs x _3sigdigit
1 0.00001616 0.00001620
2 0.00513680 0.00514000
3 35.47900000 35.50000000
4 3149.08650000 3150.00000000
Use the ABS, LOG10 and INT functions to determine the
appropriate power to use in the ROUND function in order
to round a numeric to 3 significant digits.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Mathematical
|
| Date Modified: | 2005-12-23 03:02:57 |
| Date Created: | 2004-09-30 14:09:08 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |