Sample 26045: Truncate a decimal value without rounding
Truncate a numeric value to a specified number of decimal places without rounding the value.
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.
/*******************************************************************************/
/* The following sample program uses the INT and ROUND functions to truncate */
/* the numeric value at 2 significant digits past the decimal without rounding */
/* the numeric value. */
/*******************************************************************************/
data ds1;
input x;
y=round(int(x /.01) * .01,.01);
datalines;
16.167
5.12345
.135
100.12
;
proc print;
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 y
1 16.167 16.16
2 5.123 5.12
3 0.135 0.13
4 100.120 100.12
Truncate a numeric value to a specified number of decimal places without rounding the value.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Truncation
|
| Date Modified: | 2006-03-22 03:03:10 |
| Date Created: | 2006-03-17 10:55:12 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |