```Date: Wed, 7 May 2003 16:09:57 -0400 Reply-To: Howard Schreier Sender: "SAS(r) Discussion" From: Howard Schreier Subject: Re: Difference between INT and FLOOR functions? And to make life a bit more interesting, the corresponding functions in Excel work differently. The SAS INT function displays a symmetry: INT(-x) = -INT(x). NoOt so in Excel, where INT(-1.2) = -2. The Excel CEILING and FLOOR functions each take a second argument (called "Significance") to allow for non-unity multiples. For example, CEILING(1.5,0.4) = 1.6. Excel is unhappy if the two arguments have different signs. I modeled the single-argument SAS functions CEIL and FLOOR in Excel as CEILING(x,SIGN(x)) and FLOOR(x,SIGN(x)) For x = -1.2, CEILING returns -2 and FLOOR returns -1. In other words, for these functions it is Excel which displays symmetry and SAS which does not. I became really aware of this once when I was trying to use Excel to develop a formula fragment which I intended to use in SAS. On Tue, 6 May 2003 20:30:08 -0400, Mark Lamias wrote: >Barb, > >From one Wolverine to another -- GO BLUE!. > >The FLOOR function "Returns the largest integer that is less than or equal >to the argument" which the INT function returns the integer part of the >argument. > >This can best be seen by using an example with a negative number passed to >both arguments: > >data _null_; >x=-9.4; >y=floor(x); >z=int(x); >put 'floor ' y; >put 'int ' x; >run; > >This produces the following: > >floor -10 >int -9 > >If the argument is positive, both floor and int return the same results. > >Sincerely yours, > >Mark J. Lamias >Statistical Consultant > > > > >-----Original Message----- >From: Barb Smith [mailto:brksmith@HOTMAIL.COM] >Sent: Tuesday, May 06, 2003 7:17 PM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Difference between INT and FLOOR functions? > > >Hi all, > >I am putting together a list of common functions, >what they do, and examples of how they work. > >I hope to present this as a poster or short >presentation at the next SUGI (if the University >allows me to do"international" travel). > >The two functions that I see no difference between are >INT and FLOOR. Can someone help me understand when >these two functions would return different results? > >Also, can anyone explain why the number >Y = 4.99999999999999991 shows up in the >data as 5.0000000000000000000000000000? > >Thanks so much for any help you can offer! > >Barb Smith >Senior Programmer Analyst >University of Michigan > >--------------------------------------------------- >Here is the program I used: > >data work.temp; >format y 30.28; >input y; >cards; >4.99999999999999991 >4.9999999999999991 >4.999999999999991 >4.99999999999991 >4.9999999999991 >4.999999999991 >4.99999999991 >4.9999999991 >4.999999991 >4.99999991 >4.9999991 >4.999991 >4.99991 >4.9991 >4.991 >4.91 >4.1 >; >run; > >data work.temp2; >set work.temp; >x1=int(y); >x2=ceil(y); >x3=floor(y); >x4=fuzz(y); >run; > >----------------------------------------------------- >Here is the work.temp2 table: > > y | x1 | x2 | x3 | x4 | >5.0000000000000000000000000000 | 5 | 5 | 5 | 5 >5.0000000000000000000000000000 | 5 | 5 | 5 | 5 >4.9999999999999900000000000000 | 5 | 5 | 5 | 5 >4.9999999999999100000000000000 | 5 | 5 | 5 | 5 >4.9999999999991000000000000000 | 5 | 5 | 5 | 5 >4.9999999999910000000000000000 | 4 | 5 | 4 | 5 >4.9999999999100000000000000000 | 4 | 5 | 4 | 4.9999999999 >4.9999999991000000000000000000 | 4 | 5 | 4 | 4.9999999991 >4.9999999910000000000000000000 | 4 | 5 | 4 | 4.999999991 >4.9999999100000000000000000000 | 4 | 5 | 4 | 4.99999991 >4.9999991000000000000000000000 | 4 | 5 | 4 | 4.9999991 >4.9999910000000000000000000000 | 4 | 5 | 4 | 4.999991 >4.9999100000000000000000000000 | 4 | 5 | 4 | 4.99991 >4.9991000000000000000000000000 | 4 | 5 | 4 | 4.9991 >4.9910000000000000000000000000 | 4 | 5 | 4 | 4.991 >4.9100000000000000000000000000 | 4 | 5 | 4 | 4.91 >4.1000000000000000000000000000 | 4 | 5 | 4 | 4.1 > >_________________________________________________________________ >Add photos to your messages with MSN 8. Get 2 months FREE*. >http://join.msn.com/?page=features/featuredemail ```

Back to: Top of message | Previous page | Main SAS-L page