SAS ceil/floor issues using big numbers and wanting to ceil/floor to the nearest 10,000

StackOverflow https://stackoverflow.com/questions/21168086

  •  28-09-2022
  •  | 
  •  

Question

I have one number which I need to find the ceiling and the floor value of (203,400) in order to use this number to create a weighted average. From this number I want: 200,000 and 210,000 so the code I was using that doesn't work is:

S1CovA_ceil = ceil(S1CovA,10000);
S1CovA_floor = floor(S1CovA,10000);

When I run this program, I get these errors: ERROR 72-185: The CEIL function call has too many arguments. ERROR 72-185: The FLOOR function call has too many arguments.

Does anybody know a way around this or different SAS code I could use?

Was it helpful?

Solution

CEIL and FLOOR only remove decimals - specifically rounding to integer value. If you want it rounded to (above/below) multiple of 10,000, you have to do it a bit more complicatedly:

S1CovA_ceil = ceil(s1covA/10000)*10000;

And the same for floor. Basically you have to divide it by the desired rounding level, round the rest with ceil/floor, and then multiply back.

Unfortunately, as far as I'm aware, SAS doesn't allow rounding in a particular direction except for straight integer rounding.

OTHER TIPS

You can also use the round() function...

%LET ROUNDTO = 10000 ;
data xyz ;
  S1CovA_ceil  = round(S1CovA+(&ROUNDTO / 2),&ROUNDTO) ;
  S1CovA_floor = round(S1CovA-(&ROUNDTO / 2),&ROUNDTO) ;
run ;

Try

    S1CovA_ceil = ceil(S1CovA/10000)*10000;  
    S1CovA_floor = floor(S1CovA/10000)*10000;  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top