* The usual way of computing age .
COMPUTE age1 = ( YRMODA(XDATE.YEAR(formdate),XDATE.MONTH(formdate)
,XDATE.MDAY(formdate))-YRMODA(XDATE.YEAR(bdate),XDATE.MONTH(bdate)
,XDATE.MDAY(bdate))) / 365.25 .
EXECUTE .
formats age1 (f8.2).
VARIABLE LABELS age1 "age in years: 1st method".
I have always felt there must be a less complicated way that doesn't
require one to remember so much code. Here's another method that seems
to work equally as well, and I find it much easier to remember:
* Now compute age by dividing difference between 2 dates
by the number of seconds in a year .
compute age2 = (formdate-bdate)/(60*60*24*365.25) .
execute.
formats age2 (f8.2).
VARIABLE LABELS age2 "age in years: 2nd method".
* Compare results of 2 methods .
DESCRIPTIVES
VARIABLES=age1 age2
/STATISTICS=MEAN STDDEV MIN MAX .
I have not yet tried this when the 2 date variables are formatted
differently, but it certainly appears to work when they are formatted the
same.
It is entirely possible, or even likely, that others have previously
suggested this method; so I am not touting this as something new. But it
is new and useful to me. Perhaps it will be new and useful to some others
too.
Cheers,
Bruce
--
Bruce Weaver
Clinical Epidemiology & Biostatistics
McMaster University
E-mail: wea...@fhs.csu.mcmaster.ca
Homepage: http://www.angelfire.com/wv/bwhomedir
I too have found SPSS's method of dealing with dates to be
unwieldy, but have puzzled thru it, basically to the same
approach you posted
<<I have not yet tried this when the 2 date variables are
formatted differently, but it certainly appears to work when
they are formatted the same.
I've found different date formats to be problematic.
Joel
--
Joel P. Wiesen, Ph.D., Director
Applied Personnel Research
27 Judith Road
Newton, Massachusetts 02459-1715
(617) 244-8859
Wie...@personnelselection.com
www.personnelselection.com/apr.htm
We develop personnel selection systems to be valid,
reliable, fair, practical, and legal.
Learn about our test of mechanical aptitude:
www.personnelselection.com/wtma.htm
Learn about our test of programmer/analyst aptitude:
www.personnelselection.com/programmer.htm
Formdate and bdate may have any date format, and their formats may
differ.
Jonathan Fry
SPSS Inc.
-----------------------------
> I have not yet tried this when the 2 date variables are formatted
> differently, but it certainly appears to work when they are formatted the
> same.
>
Cheers,
Bruce
> COMPUTE age1 = CTIME.DAYS(formdate-bdate)/365.25.
>
> Formdate and bdate may have any date format, and their formats may
> differ.
- That is rather astonishing!
Tell me if I am remembering wrong: I think that YRMODA does not give
the same format as what you get when you use DATEx for reading in
data .... That is the case, isn't it?
Formdate and Bdate don't have to have the same internal format? - so
the Function call OVERRIDES and PREVENTS the evaluation of the
arithmetic inside its parentheses? and converts each, as appropriate,
before subtracting and returning "days"? Well, that is impressive.
SPSS is not always so cautious with the date-types, is it?
--
Rich Ulrich, wpi...@pitt.edu
--
Rich Ulrich
http://www.pitt.edu/~wpilib/index.html
C0MPUTE mydate=YRMODA(my_year,my_month,my_day)*(86400).
The DATE.MDY and DATE.DMY functions would do the same thing given the
same variables, however, and would automatically store the result in
the SPSS date format, without the need to convert it to seconds.
Computing the difference between two dates, as long as they are
stored consistently, as Jon pointed out, is just a matter of subtracting
one from the other. The CTIME.DAYS function just acts as shorthand
for dividing the result by the 86400 seconds in a day. It thus
presumes that the difference is stored in seconds -- something that
would be true only if the two dates were stored in seconds. If
one or both of the dates involved in computing the difference were
created by the YRMODA function, the other date functions would not
be appropriate. If the two dates involved are not consistent in
this respect -- regular SPSS dates or YRMODA-created dates -- computing
their difference wouldn't be meaningful.
Most of this is discussed at various points in the "Date and Time"
section of the Universals chapter of the Syntax Reference Guide.
Hope this helps,
Ed Tverdek
Rich Ulrich <wpi...@pitt.edu> wrote in message
news:37f51b26....@usenet.pitt.edu...
Rich
YRMODA does not create a date variable and there is
no such thing as a YRMODA 'date format' ;-)
Jon,
KUDOS!
Bruce,Joel.. Doh ;-)
Forget about YRMODA! It is not a particularily useful function .
Use Date.MDY rather than YRMODA*86400.
and use CTIME rather than all that XDATE business!
Neila
Edward Tverdek wrote in message ...
--
gfsgdhfasdjhgfasd slhaslfdhaslfdjhn lafnhalsfh lSFHASLDHAS ldhslfkh
SLKHSLFDKH lshdASLKFDH LKshdlSHDLsdhSLDH skdbSDKLHsdlhDKLsjhd
Joel Wiesen ha scritto nel messaggio
<37F4B6C1...@personnelselection.com>...
>Hi Bruce,
>
>I too have found SPSS's method of dealing with dates to be
>unwieldy, but have puzzled thru it, basically to the same
>approach you posted
>
><<I have not yet tried this when the 2 date variables are
>formatted differently, but it certainly appears to work when
>they are formatted the same.
>
>I've found different date formats to be problematic.
>
>Joel
>
>
>
>
>--
>Joel P. Wiesen, Ph.D., Director
>Applied Personnel Research
>27 Judith Road
>Newton, Massachusetts 02459-1715
>(617) 244-8859
>Wie...@personnelselection.com
>www.personnelselection.com/apr.htm
>
>We develop personnel selection systems to be valid,
>reliable, fair, practical, and legal.
> Learn about our test of mechanical aptitude:
> www.personnelselection.com/wtma.htm
> Learn about our test of programmer/analyst aptitude:
> www.personnelselection.com/programmer.htm
kgjhgjhg kgkhgkhg kjgjhgf