How do you round numbers in SAS? 2

How do you round numbers in SAS?

In SAS, rounding numbers is a simple process that involves using the ROUND function. This function allows you to specify the number of decimal places to round to, as well as the direction of rounding (up or down). Additionally, SAS also has a variety of other rounding functions, such as CEIL, FLOOR, and TRUNC, which offer different methods of rounding. By using these functions, you can easily and accurately round numbers in SAS for a variety of data analysis and reporting purposes.

Round Numbers in SAS (4 Examples)


You can use the following methods to round numbers in SAS:

Method 1: Round to Nearest Integer

data new_data;
    set original_data;
    new_value = round(value);
run;

Method 2: Round to Specific Decimal Places

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;

Method 3: Round All Values Down (Or Up) to Next Integer

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;

Method 4: Round to Nearest Multiple

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;

The following examples show how to use each method with the following dataset in SAS:

/*create dataset*/
data original_data;
    input value;
    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 printdata=original_data;

Example 1: Round to Nearest Integer

The following code shows how to round each value to the nearest integer:

/*round to nearest integer*/
data new_data;
    set original_data;
    new_value = round(value);
run;

/*view new dataset*/
proc printdata=new_data;

Example 2: Round to Specific Decimal Places

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 printdata=new_data;

Example 3: Round All Values Down (Or Up) to Next Integer

The following code shows how to round all values down (or up) to the next integer using the floor() and ceil() functions:

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 printdata=new_data;

Method 4: Round to Nearest Multiple

The following code shows how to round all values to the nearest multiple of some value:

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 printdata=new_data;

Additional Resources

The following tutorials explain how to perform other common tasks in SAS:

Cite this article

stats writer (2024). How do you round numbers in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-do-you-round-numbers-in-sas/

stats writer. "How do you round numbers in SAS?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-do-you-round-numbers-in-sas/.

stats writer. "How do you round numbers in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-do-you-round-numbers-in-sas/.

stats writer (2024) 'How do you round numbers in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-do-you-round-numbers-in-sas/.

[1] stats writer, "How do you round numbers in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.

stats writer. How do you round numbers in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top