SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

I want to round numbers to close 100.

This program work fine but there are few problems:

number 750 should be rounded to 800

number 126750 should be rounded to 126800

What is the way to get correct round numbers as m requested

data t;
input x;
cards;
640
751
750
382640
41864
126750
;
run;

data new;
set t;
x_new=round(x,100);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

@Ronein wrote:

Hello

I want to round numbers to close 100.

This program work fine but there are few problems:

number 750 should be rounded to 800

number 126750 should be rounded to 126800

What is the way to get correct round numbers as m requested


i don't see a problem:

round.PNG

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

@Ronein wrote:

Hello

I want to round numbers to close 100.

This program work fine but there are few problems:

number 750 should be rounded to 800

number 126750 should be rounded to 126800

What is the way to get correct round numbers as m requested


i don't see a problem:

round.PNG

ballardw
Super User

One thing to be careful of when examining some of the results of functions is to make sure that you know the value of the variable. If you look at a result and see "750" where you think the round should give you "800" but the result is "700" then you  need to consider that the format for the variable may be hiding something from you.

 

data example;
   input x;
   rndx = round(x,100);
   format x f3.;
datalines;
749.856
750.111
;

proc print data=example;
run;

So the above in the Print output will show both values of X as 750 with different rounded values because the current format only displays 3 characters and no decimals.

 

So if the round for your actual data appears to be off, examine the base values with a format that will display a lot of decimal places, I suggest something like BEST32.

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 5615 views
  • 0 likes
  • 3 in conversation