LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 1996, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 14 Feb 1996 20:31:11 -0500
Reply-To:     West Addison <MPRNJ!JWA@MPRNJ.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         West Addison <MPRNJ!JWA@MPRNJ.COM>
Subject:      Re: DATE addition errata
In-Reply-To:  F12D8D3A0197D5D1

I just read the following post of Mark DeHaan <> of 23 Jan:

>With regard to my earlier post on DATE addition/subtraction, >it was kindly pointed out that the resulting date is _not_ >rounded, but rather truncated. (I didn't check my pgm and my personal >CPU {my mind} is pentium-like). Sorry. I wanted to note this to prevent >someone from getting bit on my account. Anyway, one _can_ round the value >if that is what you want, or print the fractional part.

In fact, it is not completely accurate to say that it is truncated (i.e., SAS Int() function), either. What actually happens is the equivalent of a SAS Floor() function. (Of course, Int() and Floor() are the same for positive numbers, but are different for negative numbers.) The following little program illustrates this:

Data _Null_; A = 1; B = 1.9; C = -1; D = -1.1; * Note this value in particular.; Put (A B C D) (Date. +1); Run;

If you run this, you will find that the output is:

02JAN60 02JAN60 31DEC59 30DEC59

If you think about it, you will see that it is completely logical that Floor() is "used" rather than Int(). If we take a value of 0 as representing midnight of 1 Jan 1960 (i.e., the very beginning of the year 1960), then a value of -1.1 would represent 9:36 p.m. on 30 Dec 1959. While this is closer to midnight of 31 Dec than it is to midnight of 30 Dec, there is no question that if you asked someone what the date was at 9:36 p.m. on 30 Dec 1959, the correct answer would be 30 Dec and not 31 Dec. This is the answer that SAS gives in the program above. If it truncated or rounded, it would "get the wrong answer" and print D as 31DEC59. (Admittedly, in some programming situations, it might be desirable to round D off to 31DEC59.) It is heartening to find that the SAS Institute has given careful thought to small details such as this.

West Addison Mathematica Policy Research, Inc. Princeton, New Jersey JWA@MPRNJ.Com

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