Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sample SAS Training 2


ROUND Function

You can use the ROUND function to round numeric values in SAS.

Let's illustrate this with an example.
Picture

The NUMBERS data set above contains a list of random numbers.


[Note: To see the NUMBERS data set on SAS Studio, run the code in the yellow box above]

Now, let's take a look at an example of the ROUND function with a rounding factor of 0.2 (2nd parameter). 

Example

Data Numbers2;
Set Numbers;
Randno2 = round(Randno, 0.2);
Run;
Picture

Wanna make a guess why the number is rounded the way it is?

The first value, 7.8209 is rounded to 7.8, which makes sense.

However, the third value, 2.6857 is rounded to 2.6. 
Picture

In fact, the ROUND function rounds the numbers to the nearest multiple of the rounding factor. 

In our example, the rounding factor is 0.2.


Randno2 = round(Randno, 0.2);


As a result, all of the rounded values are a multiple of 0.2. 
Picture

Rounding Factor: 0.3

We can also try a couple different rounding factors.

Example

Data Numbers3;
Set Numbers;
Randno2 = round(Randno, 0.3);
Run;
Picture

What if you just want to round it to 1 or 2 decimal places?

Set the rounding factor to 0.1 or 0.01. 

Example

Data Numbers4;
Set Numbers;
Randno2 = round(Randno, 0.1);
Run;
Picture

Rounding to 2 decimal places

Example

Data Numbers5;
Set Numbers;
Randno2 = round(Randno, 0.01);
Run;
Picture


Exercise

Copy and run the GROCERY data set from the yellow box below.
Picture

GROCERY contains 3 variables:
  • ITEM: Item no. 
  • PRICE: Price of the items
  • DISCOUNT: Percentage of discount for each item.


Write a SAS program to calculate the updated price based on the discount offered for each item.

The calculation should be as follow:

New = Old x (1 - Discount/100)

Round the updated price to 2 decimal places. 

Create any data set or variables if necessary.
Next

Need some help? 

Get Hint
Get Solution

Fill out my online form.
Already a member? Go to member's area.