converting numbers into dates

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

converting numbers into dates

Jean Hanson
Dear Listserve,
I have been given a dataset with dates in a 4-digit format of year and month. For example, 8901 is Jan 1989 or 0206 is Feb 2006. Is there any way to get either Excel for SPSS to read the 4-digits as a date? I have looked at date formats in both programs and this seems to be an unusual format and haven't had any luck. Thanks
Jean Hanson
Reply | Threaded
Open this post in threaded view
|

Re: converting numbers into dates

Edward Boadi
Hi Jean,

This does what you want.
Note VarOldDate is original the 4-digit year and month.

COMPUTE #VarYear =NUMBER(SUBSTR(VarOldDate,1,2),F2).
COMPUTE #VarMonth =NUMBER(SUBSTR(VarOldDate,3,2),F2).
COMPUTE  VarNewDate = DATE.MOYR(#VarMonth,#VarYear).
EXECUTE.

FORMATS  VarNewDate (MOYR8).


Thanks.

Edward.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of
Jean Hanson
Sent: Wednesday, November 22, 2006 2:57 PM
To: [hidden email]
Subject: converting numbers into dates


Dear Listserve,
I have been given a dataset with dates in a 4-digit format of year and month. For example, 8901 is Jan 1989 or 0206 is Feb 2006. Is there any way to get either Excel for SPSS to read the 4-digits as a date? I have looked at date formats in both programs and this seems to be an unusual format and haven't had any luck. Thanks
Jean Hanson
Reply | Threaded
Open this post in threaded view
|

Re: converting numbers into dates

Oliver, Richard
Alternatively:

compute newDate=date.moyr(mod(oldDate,100),trunc(oldDate/100)).
formats newDate(moyr8).

Both solutions, of course, rely on unambiguous 4-digit values; all month values must be expressed as 2-digit numbers, using a leading zero for 1-digit month values (e.g. 01, 02, 03, etc.). And the century for 2-digit year values is determined by SET EPOCH. The default epoch begins 69 years prior to the current date and ends 30 years after the current date.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Edward Boadi
Sent: Wednesday, November 22, 2006 2:30 PM
To: [hidden email]
Subject: Re: converting numbers into dates

Hi Jean,

This does what you want.
Note VarOldDate is original the 4-digit year and month.

COMPUTE #VarYear =NUMBER(SUBSTR(VarOldDate,1,2),F2).
COMPUTE #VarMonth =NUMBER(SUBSTR(VarOldDate,3,2),F2).
COMPUTE  VarNewDate = DATE.MOYR(#VarMonth,#VarYear).
EXECUTE.

FORMATS  VarNewDate (MOYR8).


Thanks.

Edward.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Jean Hanson
Sent: Wednesday, November 22, 2006 2:57 PM
To: [hidden email]
Subject: converting numbers into dates


Dear Listserve,
I have been given a dataset with dates in a 4-digit format of year and month. For example, 8901 is Jan 1989 or 0206 is Feb 2006. Is there any way to get either Excel for SPSS to read the 4-digits as a date? I have looked at date formats in both programs and this seems to be an unusual format and haven't had any luck. Thanks Jean Hanson