BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to round the number by 500 (up or down)

for example

 17524.5   will  be converted to  18000

25475.37  will  be converted to  25000

6475.3 will  be converted to  6000

 

what is the way to do it please?

 

5 REPLIES 5
LinusH
Tourmaline | Level 20
Ksharp
Super User

I think it is easy for you .

 

data have;
input have;
want=1000*round(have/1000);
cards;
17524.5  
25475.37 
6475.3 
;
proc print;run;
Patrick
Opal | Level 21

@Ronein Like below:

 

/* %let round_to=500; */
%let round_to=1000;

data test;
  do val=1,249.9,250,250.1,499.1,500,500.1,749.9,750,750.1,17524.5,25475.37,6475.3;
    round_val=round(val,&round_to);
    output;
  end;
run;

proc print data=test;
run;

Above updated after @Kurt_Bremser 's remark

 

 

Kurt_Bremser
Super User

Given your examples, you want to round by 1000, not by 500.


@Ronein wrote:

Hello

I want to round the number by 500 (up or down)

for example

 17524.5   will  be converted to  18000

25475.37  will  be converted to  25000

6475.3 will  be converted to  6000

 

what is the way to do it please?

 


 

Tom
Super User Tom
Super User

Exactly.

data have;
  input x expect;
cards;
17524.5   18000
25475.37  25000
6475.3     6000
;

data want;
  set have;
  round1000=round(x,1000);
  round500=round(x,500);
run;

Tom_0-1739371918347.png

 

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
  • 5 replies
  • 959 views
  • 4 likes
  • 6 in conversation