BookmarkSubscribeRSS Feed
CurtisER
Obsidian | Level 7

I have an user who wants to round down any values between .45 and .49.  The user doesn't want it to automatically round up to .5.

 

How do I check on decimal points only for any decimal values between .45 and .49 and then round down to .4?

 

Thank you.

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Probably ten or twelve or 134 ways to do this. Here's one:

 

round_down_variable = floor(variable*10)/10;

 

--
Paige Miller
CurtisER
Obsidian | Level 7

But how do I check for .45 - .49, then round down?

 

This floor function might work but I don't want to affect any other decimal values that aren't between .45 and .49.

FreelanceReinh
Jade | Level 19

Hello @CurtisER,

 

You could use the IFN function:

data have;
input x @@;
cards;
1.44 2.45 3.49 4.50 5.54 6.55
;

data want;
set have;
r=ifn(.45<=mod(x,1)<=.49, int(x)+.4, round(x,.1));
run;

If x can also be negative and then the same rule is to be applied, use

r=ifn(.45<=abs(mod(x,1))<=.49, int(x)+sign(x)*.4, round(x,.1));
PaigeMiller
Diamond | Level 26

@CurtisER wrote:

But how do I check for .45 - .49, then round down?

 

This floor function might work but I don't want to affect any other decimal values that aren't between .45 and .49.


You can always include an IF statement to handle just the numbers between .45 and .49

--
Paige Miller

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 215 views
  • 0 likes
  • 3 in conversation