BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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
Meteorite | Level 14

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 559 views
  • 3 likes
  • 3 in conversation