Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Easier way to compute age in years

858 views
Skip to first unread message

Bruce Weaver

unread,
Oct 1, 1999, 3:00:00 AM10/1/99
to
Hi group,
I don't know if anyone else finds calculation of age tedious in
SPSS. In the past I have always used the following to calculate age in
years:

* 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


Joel Wiesen

unread,
Oct 1, 1999, 3:00:00 AM10/1/99
to
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

Jonathan Fry

unread,
Oct 1, 1999, 3:00:00 AM10/1/99
to
COMPUTE age1 = CTIME.DAYS(formdate-bdate)/365.25.

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.
>

Bruce Weaver

unread,
Oct 1, 1999, 3:00:00 AM10/1/99
to j...@spss.com

Now that looks more like it! Thanks Jonathan.

Cheers,
Bruce

Rich Ulrich

unread,
Oct 1, 1999, 3:00:00 AM10/1/99
to
On Fri, 01 Oct 1999 12:20:37 -0500, Jonathan Fry <j...@spss.com> wrote:

> 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

Edward Tverdek

unread,
Oct 2, 1999, 3:00:00 AM10/2/99
to
Rich -- YRMODA does indeed return dates in a different format from
those returned by the other date aggregation functions. YRMODA is
kind of a legacy function; it was the only date function available
in early versions of SPSSx and in PC+ before the whole panoply of
date functions was introduced. It has always stored dates as the
number of days since the beginning of the Gregorian calendar
(midnight on October 14, 1582), while the SPSS date format that
came about later stores dates (input or computed) as *seconds* since
the beginning of the Gregorian calendar. It's easy enough to convert
a date computed with YRMODA to the standard SPSS date format; you can
just multiply the computed value by the number of seconds in a day:

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...

Neila Nessa

unread,
Oct 3, 1999, 3:00:00 AM10/3/99
to
Ed,
Actually , it was Pre SPSS-X (SPSS) that YRMODA was the
lonely 'date-function'.

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 ...

SaintJust

unread,
Oct 6, 1999, 3:00:00 AM10/6/99
to

--
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


0 new messages