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

Dear friends,

 

I have depth which increases by 0.5.

 

I like to join it to other numbers which are real numbers.

 

I like to round my real numbers to closest integer or 0.5 which can be joined to my integer numbers.

 

The rules are:

 

Decimals between 0 and 25 will be round down to 0 (22.25 will be 22.0)

Decimals between 26 and 49 will be round up to 50 (22. 27 will be 22.50)

Decimals between 51 and 75 will be round down to 50 (22. 57 will be 22.50) 

Decimals between 76 and 99 will be round up to whole number (22. 77 will be 23.0) 

 

Let's look at my numbers. I have the following table

 

Table1

depth
0,18
0,56
1,12
1,45
5,25
5,26
6,66
7,11
8,67
9,11
10,67

 

I like the above table be like this:

Table2

depth
0,0
0,5
1,0
1,5
5,0
5,5
7,0
7,0
8,5
9,0
10,5

 

Can you please help me with it?

 

Thank you very much!

 

Best regards

 

Farshid Owrang 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your posted results don't follow your rules. 8.67 should go to 8.5 not 9.0. 8.76 would round up to 9.

 

You can use ROUND() function to round to the nearest 0.5.  To force the .25 and .75 to round down instead of up subtract a small delta.

want=round(depth-0.001,0.5);

View solution in original post

5 REPLIES 5
andreas_lds
Jade | Level 19

The want-table is not conform to the description.In the last line you have 10.67, according to the description ("Decimals between 51 and 75 will be round down to 50 (22. 57 will be 22.50) ") the result should be 10.5, not 11.0. If 10.5 is the right result, then use the round function with 0.5 as second parameter.

farshidowrang
Quartz | Level 8

Sorry

 

You are completely right

 

It should be 10.5

 

Thank you very much

 

I will fix it in the table

 

Thank you

Tom
Super User Tom
Super User

Your posted results don't follow your rules. 8.67 should go to 8.5 not 9.0. 8.76 would round up to 9.

 

You can use ROUND() function to round to the nearest 0.5.  To force the .25 and .75 to round down instead of up subtract a small delta.

want=round(depth-0.001,0.5);
farshidowrang
Quartz | Level 8

Dear friend

 

It seems it works

 

Thank you very much 

 

Best regards

 

Farshid Owrang 

 

 

Reeza
Super User
Please select the correct answer, not this response, and mark it as the solution to let others know this is solved.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4130 views
  • 5 likes
  • 4 in conversation