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

I can test this now, but I think this would come close enough:

 

var = round(var - 1e-12, 0.01);

 

buddha_d
Pyrite | Level 9

Man, Astounding awesome. Could you please give me logic for this??

 

thanks a ton......

Astounding
PROC Star

The basic idea is to round to the nearest 0.01.  That would solve most of the problem, except that standard rounding would round 0.015 to 0.02 instead of 0.01.  So subtract a tiny amount, and then round to the nearest 0.01.  If you actually have a value that is 0.0150000000001, this formula will be incorrect and will round to 0.01 instead of 0.02.  The "tiny amount" being subtracted would be enough to alter the result.

buddha_d
Pyrite | Level 9

How can I adjust the formula for varying digits (bold letters) for eg:

data new;
input x;
var = round(x - 1e-12, 0.01);
cards;
0.0750001
0.0750000
0.0755920
0.0744999
0.0700001
0.050000001
0.049999999
;
run;

 

the results are: 

 

0.08

0.07

0.08

0.07

0.07

0.05

0.05

 

Astounding
PROC Star

The next-to-last observation should be fine as is.  The last observation is asking for a new set of rules, and you haven't presented any such rules.  Here is another approach you can experiment with:

 

var = round(var, 0.00000001);

var = round(var, 0.01);    or possibly   var = round(var - 1e-10, 0.01);

 

By rounding twice, the 0.049999999 would become 0.05, then the second rounding wouldn't change the value.  You might have to experiment with the number of decimal places to use in the first rounding, and whether you want to subtract that tiny amount for the second rounding.

buddha_d
Pyrite | Level 9
Kudos Astounding !!!!!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 20 replies
  • 12780 views
  • 0 likes
  • 5 in conversation