BookmarkSubscribeRSS Feed
Nietzsche
Lapis Lazuli | Level 10

FLOOR function returns the largest integer that is less than or equal to the argument while INT function removes any values after the decimal places.

 

So in terms of the final result, ain't they exact the same? Are there any situations where you should one function over the other?

 

see example with sashelp.tourism

 

data temp;
	set sashelp.tourism;
		floor = floor(vsp);
		int = int(vsp);
run;

proc print data=temp;
var vsp floor int;
run;

Nietzsche_0-1671098871560.png

 

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

No. Consider the case of negative numbers. In that case, the results will differ

 

data have;
   do _N_ = 1 to 10;
      x = rand('uniform', -10, 10);
      output;
   end;
   format x 8.2;
run;

data want;
   set have;
   int   = int(x);
   floor = floor(x);
run;
PaigeMiller
Diamond | Level 26

According to the INT documentation (which you should be reading before you ask, @Nietzsche)

 

The INT function returns the integer portion of the argument (truncates the decimal portion). If the argument's value is within 1E-12 of an integer, the function results in that integer. If the value of argument is positive, the INT function has the same result as the FLOOR function. If the value of argument is negative, the INT function has the same result as the CEIL function.

--
Paige Miller
Rick_SAS
SAS Super FREQ

@PeterClemmensen has given the most important difference. For more information about various ways to round numbers in SAS, see "Rounding up, rounding down."

 

Engineers often use a method known as the round-to-even method, which is also supported in SAS.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 7307 views
  • 4 likes
  • 4 in conversation