Old code to compute age from dates (was it Art Kendall's?)

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Old code to compute age from dates (was it Art Kendall's?)

Melissa Ives
These all seem very complicated.
Pre version 14, we used the following format.
SPSS stores dates as seconds from the start of the Gregorian calendar.
There are 86400 seconds in a day and 365.25 days in a year.
Age does not increase until the birth date has passed, so truncate Is use.

compute age=trunc(((StudyDate-DateOfBirth)/86400)/365.25).

Melissa Ives

Roberts, Michael-2 wrote

> Not sure whether this is what you wanted, but it is old and I believe
> by RRistow.
>
> /* Calculate age (in years and fraction of years) on June 30,2000.*/
> COMPUTE age=CTIME.DAYS(DATE.DMY(30,6,2000)-dob)/365.25.
> EXECUTE.
>
> Data were in the following format:
>
> 1940-10-09 2000-10-09 1980-01-07 2000-10-10
> 1952-10-01 2000-10-09 1980-01-07 2000-10-10
>
> Or alternatively:
>
> COMPUTE Age=DATEDIFF($TIME, BirthDate, 'years'). (not sure who the
> author was on this one! Sorry!)
>
> Hope it helps.
>
> Mike
>
>
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of Marta García-Granero
> Sent: Wednesday, December 05, 2012 9:59 AM
> To:

> SPSSX-L@.UGA

> Subject: Old code to compute age from dates (was it Art Kendall's?)
>
> Hi:
>
> This is the Stata User Formerly Known As an SPSS Macro Programmer
> (SUFKASP).
>
> Since SPSS 13 I use(d) DATEDIF to compute age from two dates. Stata
> users seem to keep on using the old formula:
> int(StudyDate-DateOfBirth)/365.25 (since Stata stores dates as days,
> it is easier than the SPSS counterpart, that required CTIME.DAYS to
> convert seconds to days).
>
> I recall that years ago we had an interesting thread concerning the
> errors this method could cause in some cases. I had and slightly
> improved
> version:
>
> INT(CTIME.DAYS(1+StudyDate-DateOfBirth)/365.25)
>
> That avoided some errors, but not all of them.
>
> There was a short syntax that computed ages correctly before SPSS 13.
> It looks that I did not keep a copy of it (bad idea..) because of DATEDIF.
> I would like to have it again to translate it to a Stata do file.
>
> Does anybody keep it yet?
>
> Thanks in advance
>
> Marta GG (SUFKASP)
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the command. To leave the
> list, send the command SIGNOFF SPSSX-L For a list of commands to
> manage subscriptions, send the command INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the command. To leave the
> list, send the command SIGNOFF SPSSX-L For a list of commands to
> manage subscriptions, send the command INFO REFCARD





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Old-code-to-compute-age-from-dates-was-it-Art-Kendall-s-tp5716678p5716880.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Old code to compute age from dates (was it Art Kendall's?)

David Marso
Administrator
Please review the thread and note the off by one day issue!
--
Melissa Ives wrote
These all seem very complicated.
Pre version 14, we used the following format.
SPSS stores dates as seconds from the start of the Gregorian calendar.
There are 86400 seconds in a day and 365.25 days in a year.
Age does not increase until the birth date has passed, so truncate Is use.

compute age=trunc(((StudyDate-DateOfBirth)/86400)/365.25).

Melissa Ives

Roberts, Michael-2 wrote
> Not sure whether this is what you wanted, but it is old and I believe
> by RRistow.
>
> /* Calculate age (in years and fraction of years) on June 30,2000.*/
> COMPUTE age=CTIME.DAYS(DATE.DMY(30,6,2000)-dob)/365.25.
> EXECUTE.
>
> Data were in the following format:
>
> 1940-10-09 2000-10-09 1980-01-07 2000-10-10
> 1952-10-01 2000-10-09 1980-01-07 2000-10-10
>
> Or alternatively:
>
> COMPUTE Age=DATEDIFF($TIME, BirthDate, 'years'). (not sure who the
> author was on this one! Sorry!)
>
> Hope it helps.
>
> Mike
>
>
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of Marta García-Granero
> Sent: Wednesday, December 05, 2012 9:59 AM
> To:

> SPSSX-L@.UGA

> Subject: Old code to compute age from dates (was it Art Kendall's?)
>
> Hi:
>
> This is the Stata User Formerly Known As an SPSS Macro Programmer
> (SUFKASP).
>
> Since SPSS 13 I use(d) DATEDIF to compute age from two dates. Stata
> users seem to keep on using the old formula:
> int(StudyDate-DateOfBirth)/365.25 (since Stata stores dates as days,
> it is easier than the SPSS counterpart, that required CTIME.DAYS to
> convert seconds to days).
>
> I recall that years ago we had an interesting thread concerning the
> errors this method could cause in some cases. I had and slightly
> improved
> version:
>
> INT(CTIME.DAYS(1+StudyDate-DateOfBirth)/365.25)
>
> That avoided some errors, but not all of them.
>
> There was a short syntax that computed ages correctly before SPSS 13.
> It looks that I did not keep a copy of it (bad idea..) because of DATEDIF.
> I would like to have it again to translate it to a Stata do file.
>
> Does anybody keep it yet?
>
> Thanks in advance
>
> Marta GG (SUFKASP)
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the command. To leave the
> list, send the command SIGNOFF SPSSX-L For a list of commands to
> manage subscriptions, send the command INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the command. To leave the
> list, send the command SIGNOFF SPSSX-L For a list of commands to
> manage subscriptions, send the command INFO REFCARD





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Old-code-to-compute-age-from-dates-was-it-Art-Kendall-s-tp5716678p5716880.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Old code to compute age from dates (was it Art Kendall's?)

Art Kendall
the example syntax I posted compares 4 methods of computing age.
Art Kendall
Social Research Consultants
On 12/11/2012 2:57 PM, David Marso wrote:
Please review the thread and note the off by one day issue!
--

Melissa Ives wrote
These all seem very complicated.
Pre version 14, we used the following format.
SPSS stores dates as seconds from the start of the Gregorian calendar.
There are 86400 seconds in a day and 365.25 days in a year.
Age does not increase until the birth date has passed, so truncate Is use.

compute age=trunc(((StudyDate-DateOfBirth)/86400)/365.25).

Melissa Ives

Roberts, Michael-2 wrote
Not sure whether this is what you wanted, but it is old and I believe
by RRistow.

/* Calculate age (in years and fraction of years) on June 30,2000.*/
COMPUTE age=CTIME.DAYS(DATE.DMY(30,6,2000)-dob)/365.25.
EXECUTE.

Data were in the following format:

1940-10-09 2000-10-09 1980-01-07 2000-10-10
1952-10-01 2000-10-09 1980-01-07 2000-10-10

Or alternatively:

COMPUTE Age=DATEDIFF($TIME, BirthDate, 'years'). (not sure who the
author was on this one! Sorry!)

Hope it helps.

Mike




-----Original Message-----
From: SPSSX(r) Discussion [mailto:

        
[hidden email]

        
] On Behalf Of Marta García-Granero
Sent: Wednesday, December 05, 2012 9:59 AM
To:

        
[hidden email]

        
Subject: Old code to compute age from dates (was it Art Kendall's?)

Hi:

This is the Stata User Formerly Known As an SPSS Macro Programmer
(SUFKASP).

Since SPSS 13 I use(d) DATEDIF to compute age from two dates. Stata
users seem to keep on using the old formula:
int(StudyDate-DateOfBirth)/365.25 (since Stata stores dates as days,
it is easier than the SPSS counterpart, that required CTIME.DAYS to
convert seconds to days).

I recall that years ago we had an interesting thread concerning the
errors this method could cause in some cases. I had and slightly
improved
version:

INT(CTIME.DAYS(1+StudyDate-DateOfBirth)/365.25)

That avoided some errors, but not all of them.

There was a short syntax that computed ages correctly before SPSS 13.
It looks that I did not keep a copy of it (bad idea..) because of
DATEDIF.
I would like to have it again to translate it to a Stata do file.

Does anybody keep it yet?

Thanks in advance

Marta GG (SUFKASP)

=====================
To manage your subscription to SPSSX-L, send a message to

        
[hidden email]

        
 (not to SPSSX-L), with no body text except the command. To leave the
list, send the command SIGNOFF SPSSX-L For a list of commands to
manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to

        
[hidden email]

        
 (not to SPSSX-L), with no body text except the command. To leave the
list, send the command SIGNOFF SPSSX-L For a list of commands to
manage subscriptions, send the command INFO REFCARD




-----
--
Bruce Weaver

      
bweaver@

      
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Old-code-to-compute-age-from-dates-was-it-Art-Kendall-s-tp5716678p5716880.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to

      
[hidden email]

      
 (not to SPSSX-L), with no body text except the command. To leave the
list, send the command SIGNOFF SPSSX-L For a list of commands to manage
subscriptions, send the command INFO REFCARD

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

=====================
To manage your subscription to SPSSX-L, send a message to

      
[hidden email]

      
 (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD




-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Old-code-to-compute-age-from-dates-was-it-Art-Kendall-s-tp5716678p5716884.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Old code to compute age from dates (was it Art Kendall's?)

Jarrod Teo-2
Hi,
 
Here is the one I have been using which takes into account whether the respondent passes his birthday or not. The do-if end-if checks that based on the daydiff which takes into account the month and days.
 
Hope this helps.
 
*Assuming that the birthdate is in string.
*age of respondent as of 30th Nov 2012.
 
compute bday=number(substring(BirthDate,1,2),f2).
compute bmonth=number(substring(BirthDate,4,2),f2).
compute byear=number(substring(BirthDate,7,4),f4).
fre bday to byear.
 
compute agedraft=2012-byear.
exe.

compute daydiff=((30*11+30)-(31*bmonth+bday)).
exe.
 
do if (daydiff lt 0).
compute age=agedraft-1.
else if (daydiff ge 0).
compute age=agedraft.
end if.
exe.

 
Warmest Regards
Dorraj Oet
 

Date: Tue, 11 Dec 2012 18:16:55 -0500
From: [hidden email]
Subject: Re: Old code to compute age from dates (was it Art Kendall's?)
To: [hidden email]

the example syntax I posted compares 4 methods of computing age.
Art Kendall
Social Research Consultants
On 12/11/2012 2:57 PM, David Marso wrote:
Please review the thread and note the off by one day issue!
--

Melissa Ives wrote
These all seem very complicated.
Pre version 14, we used the following format.
SPSS stores dates as seconds from the start of the Gregorian calendar.
There are 86400 seconds in a day and 365.25 days in a year.
Age does not increase until the birth date has passed, so truncate Is use.

compute age=trunc(((StudyDate-DateOfBirth)/86400)/365.25).

Melissa Ives

Roberts, Michael-2 wrote
Not sure whether this is what you wanted, but it is old and I believe
by RRistow.

/* Calculate age (in years and fraction of years) on June 30,2000.*/
COMPUTE age=CTIME.DAYS(DATE.DMY(30,6,2000)-dob)/365.25.
EXECUTE.

Data were in the following format:

1940-10-09 2000-10-09 1980-01-07 2000-10-10
1952-10-01 2000-10-09 1980-01-07 2000-10-10

Or alternatively:

COMPUTE Age=DATEDIFF($TIME, BirthDate, 'years'). (not sure who the
author was on this one! Sorry!)

Hope it helps.

Mike




-----Original Message-----
From: SPSSX(r) Discussion [mailto:

[hidden email]

] On Behalf Of Marta García-Granero
Sent: Wednesday, December 05, 2012 9:59 AM
To:

[hidden email]

Subject: Old code to compute age from dates (was it Art Kendall's?)

Hi:

This is the Stata User Formerly Known As an SPSS Macro Programmer
(SUFKASP).

Since SPSS 13 I use(d) DATEDIF to compute age from two dates. Stata
users seem to keep on using the old formula:
int(StudyDate-DateOfBirth)/365.25 (since Stata stores dates as days,
it is easier than the SPSS counterpart, that required CTIME.DAYS to
convert seconds to days).

I recall that years ago we had an interesting thread concerning the
errors this method could cause in some cases. I had and slightly
improved
version:

INT(CTIME.DAYS(1+StudyDate-DateOfBirth)/365.25)

That avoided some errors, but not all of them.

There was a short syntax that computed ages correctly before SPSS 13.
It looks that I did not keep a copy of it (bad idea..) because of
DATEDIF.
I would like to have it again to translate it to a Stata do file.

Does anybody keep it yet?

Thanks in advance

Marta GG (SUFKASP)

=====================
To manage your subscription to SPSSX-L, send a message to

[hidden email]

 (not to SPSSX-L), with no body text except the command. To leave the
list, send the command SIGNOFF SPSSX-L For a list of commands to
manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to

[hidden email]

 (not to SPSSX-L), with no body text except the command. To leave the
list, send the command SIGNOFF SPSSX-L For a list of commands to
manage subscriptions, send the command INFO REFCARD



-----
--
Bruce Weaver

bweaver@

http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Old-code-to-compute-age-from-dates-was-it-Art-Kendall-s-tp5716678p5716880.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to

[hidden email]

 (not to SPSSX-L), with no body text except the command. To leave the
list, send the command SIGNOFF SPSSX-L For a list of commands to manage
subscriptions, send the command INFO REFCARD

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

=====================
To manage your subscription to SPSSX-L, send a message to

[hidden email]

 (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Old-code-to-compute-age-from-dates-was-it-Art-Kendall-s-tp5716678p5716884.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Old code to compute age from dates (was it Art Kendall's?)

Richard Ristow
In reply to this post by Barnett, Adrian (DECD)
A footnote, on the length of the year:

At 04:51 PM 12/5/2012, Barnett, Adrian (DECD) wrote:

>(1)     the correct number of days in the average year, to account
>for leap years, is 365.2425, not 365.25.  There are in fact fewer
>than one leap year every four years, because there are exceptions
>applied to century years such as 2000.  Using 365.25 for the number
>of days in a year is the system used in the superseded Julian
>calendar, whereas the Gregorian calendar we now use employs 365.2425.

That is correct, over the whole run of the Gregorian calendar.
However, year 2000 is one of the end-of-century years that *is* a
leap year in the Gregorian calendar (because it's divisible by 400).
Therefore, over the range of years 1901-2099 (a span which covers
most age calculations we'll need), the average length of year is 365.25 days.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
12