BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Perhaps it quite simple, but I need to easily convert my data in multiples of 100 only like 619 should be 600, 754 should be 700,1238976 should be 1238900. Any easy fix? Thanks a lot.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Is the round down what you want? or just round? 

 

If it's ROUND, then use the ROUND() Function with 100 as the second parameter.

 

If it's floor, you need to divide by 100, floor it, and then multiply by 100.

 

answer1 = round(original, 100);
answer2 = floor(original/100)*100;

 

 

View solution in original post

4 REPLIES 4
Reeza
Super User

Is the round down what you want? or just round? 

 

If it's ROUND, then use the ROUND() Function with 100 as the second parameter.

 

If it's floor, you need to divide by 100, floor it, and then multiply by 100.

 

answer1 = round(original, 100);
answer2 = floor(original/100)*100;

 

 

rajeshalwayswel
Pyrite | Level 9

I have small doubt on the

answer1 = round(619, 100);
answer1=600;

how we are getting 600 can someone explain it...

can you please explain it..

 

I have understand in this method
x=round(223.456,.3);

Result:

x=223.5

In the above I have understand that

first step: 223.456*0.3=67.0368
second step :round(67.0368)=67.368
third step : 67.368/0.3=223.5

 

Reeza
Super User

 

@rajeshalwayswel

 

Rounds the first argument to the nearest multiple of the second argument, or to the nearest integer when the second argument is omitted.

 

 

So in 619, the nearest 100 is 600 and 700. Because 600 is closer, it's rounded to 600. 

 

Your interpretation/logic appears incorrect - run the code. 

first step: 223.456*0.3=67.0368
second step :round(67.0368)=67.368 -> This would result in 67, not 67.368. 
third step : 67.368/0.3=223.5

 

My interpretation was always, figure out how many exact values of the second parameter fit in and then round up or down as necessary. 

 

 

The logic in my head is, assuming ROUND(P1, P2) is equivalent to:

 

Value = round(P1/P2,1) * P2 ;

 

 

At least for positive values. Here's some demo code that can help illustrate this. 

 

data demo;
 x=round(223.456, .3);
 y=223.456/0.3;
 z=round(y, 1);
 w=z*0.3;
 x1=round(67.0368);
 test=round(223.456/0.3)*0.3;
 test2=round(619, 100);
run;

@rajeshalwayswel wrote:

I have small doubt on the

answer1 = round(619, 100);
answer1=600;

how we are getting 600 can someone explain it...

can you please explain it..

 

I have understand in this method
x=round(223.456,.3);

Result:

x=223.5

In the above I have understand that

first step: 223.456*0.3=67.0368
second step :round(67.0368)=67.368
third step : 67.368/0.3=223.5

 


 

rajeshalwayswel
Pyrite | Level 9

Thank you.. It very clear..

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 4 replies
  • 785 views
  • 2 likes
  • 3 in conversation