LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2005)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 23 Jun 2005 12:39:40 -0400
Reply-To:   "Katkowski, David" <>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   "Katkowski, David" <>
Subject:   Re: ACCESS to SPSS question
Comments:   To: John Norton <>
Content-Type:   text/plain; charset="us-ascii"

Or, you could do it all in one command without parsing and creating extra variables. This is courtesy of Nelia Nessa from spss newsgroup:

< ad/thread/4d91130cc3f581a5>

If your format is 01jan1989, do the following:

COMPUTE DATEVAR= NUMBER(CONCAT(SUBSTR(strdate,1,2),"-",SUBSTR(strdate,3,3),"-",SUBSTR(str date,6)), DATE11). FORMATS DATEVAR(DATE11).

If your format is different, replace the start and length parameters in the substring functions.

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of John Norton Sent: Thursday, June 23, 2005 12:27 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: ACCESS to SPSS question

Hi Shimy,

If it is a text field to begin with, I'd read the Access file into SPSS (I prefer ODBC, but there are other ways as well) and after the file is successfully in SPSS, I'd parse out the text information in the text field into month, day and year variables, and then use a date function to put them all back together into a valid date filed.

The commands for this aren't difficult to generate, but we'd need a better idea of what your date information looks like once it's in SPSS before we approach the puzzle. For example, does the date look like, "JAN-01-2005" or "01/01/05" or "January 1, 2005". The form that the text information takes is essential to know before proceeding, but following is an example for one way to tackle the problem (assuming the text information takes on an American date format of 8 characters in length, like "01/01/05")

* these 3 COMPUTE commands will create 3 new variables and store the * month, day and year values in numeric format. COMPUTE month = NUMBER(SUBSTR(textdate,1,2),F2). COMPUTE day = NUMBER(SUBSTR(textdate,4,2),F2). COMPUTE year = NUMBER(SUBSTR(textdate,7,2),F2).

* Next, use the DATE.MDY() function to combine the month, day and year * values into a valid date filed. COMPUTE new_date = DATE.MDY(month,day,year). EXE.

* Finally format that new variable so it takes the American Date format again. FORMATS new_date (ADATE8).

Now, if you don't want 4 new variables - month, day, year and new_date - you can use the functions in the first 3 compute statements for the last compute command, which actually creates the date variable, thus:

COMPUTE new_date = DATE.MDY((NUMBER(SUBSTR(textdate,1,2),F2)),

(NUMBER(SUBSTR(textdate,4,2),F2)),(NUMBER(SUBSTR(textdate,7,2),F2))). EXE. FORMATS new_date (ADATE8).



>>> Shimy Apoorva <sxa6137@BJC.ORG> 6/23/2005 11:11 AM >>>

Hello All, I have an Access file. One of the fields in that file is a text field. This field should have ideally been a date/time field. Is there a way when I am exporting this file to SPSS, I change the type of field fro text to date/time without losing the data.

Thanks, Shimy.

Back to: Top of message | Previous page | Main SPSSX-L page