BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to round down by 500.

for example:

870 will be rounded to 500

1020 will be rounded to 1000

2580 will be rounded to 2500

2900 will be rounded to  to 2500

what is the way to do it please?

 

data t;
input x;
cards;
870
1020
2580
2900
;
run;
data t2;
set t;
newvalue1 = round(x,500);
 run;

 

 

 

3 REPLIES 3
Ronein
Onyx | Level 15

I  know this way but maybe have better solution

data t2;
set t;
newvalue1 = round(x,500);
if newvalue1>x then newvalue2=newvalue1-500;else newvalue2=newvalue1;
 run;
PeterClemmensen
Tourmaline | Level 20

How about

 

data t;
input x;
cards;
870
1020
2580
2900
;

data want;
   set t;
   y = x - mod(x, 500);
run;
PaigeMiller
Diamond | Level 26

As you see, the ROUND function doesn't round down, it rounds to the nearest 500. The fix is:

 

newvalue1 = round(x-250,500);
--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1134 views
  • 3 likes
  • 3 in conversation