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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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