Date: Sun, 29 Apr 2001 09:42:03 -1000
Reply-To: Richard Severino <severino@HAWAII.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Richard Severino <severino@HAWAII.EDU>
Subject: Re: SPSS to SAS date conversion
SPSS handles its dates as follows:
SPSS reads and writes date and time in many different formats but
stores them as
A date is a floating-point number representing the number of
seconds from midnight,
October 14, 1582. Dates, which represent a particular point in
time, are stored as the
number of seconds to that date. For example, November 8, 1957, is
stored as 1.2E+10.
A date includes the time of day, which is the time interval past
midnight. When time
of day is not given, it is taken as 00:00 and the date is an even
multiple of 86,400
(the number of seconds in a day).
so in fact, your trial and error resulted in discovering some of the truth
about SPSS dates.
And so one would conclude that when creating an SPSS portable file that
included dates, the dates would all be very large floating point numbers...
right? ... WRONG !
if the SPSS date format used in the SPSS file is DATE11 (which seems to be
the SPSS default) of dd-mmm-yyyy (example: 01-JAN-1999) .. then the date in
the portable file will be as you found: a large number representing the
number of seconds from midnight Oct 14 1582.
if the format for the date in SPSS is ADATE10 or ADATE8 ( mm/dd/yyyy or
mm/dd/yy ) then the resulting date in the portable file will be read by SAS
as a having format DATE7.
so I guess if one has no knowledge of the date format used in SPSS, after
reading the portable file in SAS, one has to check as the date field. If it
was read as a floating point on the order of 1E10 ... then it is probably
safe to assume that it is the number of seconds from oct 14 1582. In this
case, dividing by 86400 yields the number of days between Oct 14 1582 and
the date iteself. With this knowledge it is easy to have SAS compute the
date by deleting (or subtracting) the appropriate number of days from
whatever the current date is.
days = datespss/86400 ;
datesas = date() - ( date() - MDY(10,14,1582) - days ) ;
There are I am sure other ways of dealing with this issue.
One way I have seen for dealing with passing dates from SPSS to SAS is to
convert the date in SPSS to a Julian Date, then use the julian date
functions in SAS to get the date back.
I hope this helps clear up the mystery :)
At 04:25 AM 4/28/01 -1000, John Whittington wrote:
>I was recently sent data in the form of a small SPSS (release 8) .sav file,
>which was of no use to me. I therefore got a kindly soul to convert it to
>a .por file, which I was then able to import into SAS (v8) using the SPSS
>What I ended up with seemed generally credible. However, one of the
>variables was 'date of birth' and that appeared as 'very large numbers' (of
>the order 1E10). I concluded that if these were anything that SAS
>understood, they would have to be SAS datetime variables. Using that
>assumption, I applied a datetime format and ended up with dates in the 24th
>I therefore then got my friend to provide a conversion of the original .sav
>file to an Excel one, which I can read. As I result, I discovered that the
>dates I obtained by the 'conversion to SAS' (and assuming that they had
>ended up as SAS datetime variables) were systematically different from
>those in the Excel conversion ....
>.... I discovered by trial and error that I could get the two sets of dates
>to correspond to one another by adding 719,020,800 (aka '14OCT82:00:00'dt)
>to the presumed SAS datetime variables I had ended up with after
>conversion. This implies that the converted data was totally analagous to
>SAS datetime variables, but with and 'origin' of 23rd March 1937.
>Does any of that make any sense to anyone? What I obviously need to do now
>is to get my friend to look at the original SPSS file and confirm that the
>dates I am now looking at are actually correct, which I will do after the
>weekend. However, in the meantime, I am a little intrigued by the
>mechanics of whatever is going on!
>Dr John Whittington, Voice: +44 (0) 1296 730225
>Mediscience Services Fax: +44 (0) 1296 738893
>Twyford Manor, Twyford, E-mail: John.W@mediscience.co.uk
>Buckingham MK18 4EL, UK email@example.com