Ceiling and Floor Computation in SPSS

Someone forgot to add CEILING and FLOOR functions to SPSS. Thankfully with a little logic and rounding, we can accomplish the same thing.

Antti Nevanlinna posted this solution on mathkb.com:

floor(x) = rnd(x) – 1*(rnd(x) > x)
ceil(x) = rnd(x) + 1*(rnd(x) < x)

The function rnd is a rounding function that does what you would expect: up for >= .50 and down for < .50.
The expression (rnd(x) < x) is a logical statement that will evaluate to 1 if true and 0 if false.

I am posting it here as a reminder for myself and as a service to anyone else looking to do the same thing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s