如何在 SAS 中对数字进行四舍五入(4 个示例) | 您所在的位置:网站首页 › 1354999四舍五入 › 如何在 SAS 中对数字进行四舍五入(4 个示例) |
如何在 sas 中对数字进行四舍五入(4 个示例)经过 本杰明·安德森博
7月 21, 2023
指导
0 条评论 您可以使用以下方法对 SAS 中的数字进行四舍五入: 方法 1:四舍五入到最接近的整数 data new_data; set original_data; new_value = round (value); run ;方法2:四舍五入到特定小数位 data new_data; set original_data; new_value1 = round (value, .1); /*round to 1 decimal place*/ new_value2 = round (value, .01); /*round to 2 decimal places*/ new_value3 = round (value, .001); /*round to 3 decimal places*/ run ;方法3:将所有值向下(或向上)舍入到下一个整数 data new_data; set original_data; new_value1 = floor (value); /*round down to next integer*/ new_value2 = ceil (value); /*round up to next integer*/ run ;方法 4:四舍五入到最接近的倍数 data new_data; set original_data; new_value1 = round (value, 10); /*round to nearest multiple of 10*/ new_value2 = round (value, 100); /*round to nearest multiple of 100*/ run ;以下示例展示了如何在 SAS 中对以下数据集使用每种方法: /*create dataset*/ data original_data; inputvalue ; datalines ; 0.33 0.9 1.2593 1.61 2.89 4.3 8.8 14.4286 18.2 51.4 ; run ; /*view dataset*/ proc print data = original_data; 示例 1:四舍五入到最接近的整数以下代码显示如何将每个值舍入为最接近的整数: /*round to nearest integer*/ data new_data; set original_data; new_value = round (value); run ; /*view new dataset*/ proc print data = new_data; 示例 2:四舍五入到特定小数位以下代码展示了如何将值四舍五入到特定的小数位数: data new_data; set original_data; new_value1 = round (value, .1); /*round to 1 decimal place*/ new_value2 = round (value, .01); /*round to 2 decimal places*/ new_value3 = round (value, .001); /*round to 3 decimal places*/ run ; /*view new dataset*/ proc print data = new_data; 示例 3:将所有值向下(或向上)舍入到下一个整数下面的代码展示了如何使用floor()和ceil()函数将所有值向下(或向上)舍入: data new_data; set original_data; new_value1 = floor (value); /*round down to next integer*/ new_value2 = ceil (value); /*round up to next integer*/ run ; /*view new dataset*/ proc print data = new_data; 方法 4:四舍五入到最接近的倍数以下代码展示了如何将所有值四舍五入到某个值的最接近倍数: data new_data; set original_data; nearest10 = round (value, 10); /*round to nearest multiple of 10*/ nearest100 = round (value, 100); /*round to nearest multiple of 100*/ run ; /*view new dataset*/ proc print data = new_data; 其他资源以下教程解释了如何在 SAS 中执行其他常见任务: 如何标准化 SAS 中的数据SAS中如何用零替换缺失值SAS中如何删除重复项 关于作者本杰明·安德森博大家好,我是本杰明,一位退休的统计学教授,后来成为 Statorials 的热心教师。 凭借在统计领域的丰富经验和专业知识,我渴望分享我的知识,通过 Statorials 增强学生的能力。了解更多 添加评论取消回复 |
CopyRight 2018-2019 实验室设备网 版权所有 |