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 (December 2007)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 20 Dec 2007 13:27:05 -0600
Reply-To:   "Oliver, Richard" <roliver@spss.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   "Oliver, Richard" <roliver@spss.com>
Subject:   Re: STRING TO DATE?
Comments:   To: Ariel Barak <abarakabarak@gmail.com>
Content-Type:   text/plain; charset="iso-8859-1"

In this case, I think only the first two lines of method 2 are needed: COMPUTE mydate=NUMBER(datestr,ADATE10). FORMATS mydate(ADATE10).

________________________________

From: SPSSX(r) Discussion on behalf of Ariel Barak Sent: Thu 12/20/2007 1:05 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: STRING TO DATE?

Sydelle,

The text below is copied from Raynald's SPSS Tools website -

http://www.spsstools.net/LearningSyntax.htm#DateTutorial

HTH, Ariel

** 3. Convert a string containing a date into a date variable.*

DATA LIST LIST /datestr(A10). BEGIN DATA 11/26/1966 01/15/1981 END DATA. LIST. *

--> method 1* (a general method)

COMPUTE mth=NUMBER(SUBSTR(datestr,1,2),F8.0). COMPUTE day=NUMBER(SUBSTR(datestr,4,2),F8.0). COMPUTE yr=NUMBER(SUBSTR(datestr,7),F8.0). COMPUTE mydate=DATE.DMY(day,mth,yr). FORMAT mydate(SDATE11). VARIABLE WIDTH mydate (11). EXECUTE.

* The date in the above string variable has the form mm/dd/yyyy. The code works as * is if the initial format is mm.dd.yyyy or mm-dd-yyyy. It is easy to modify the above * to handle variations such as yyyy/mm/dd, dd/mm/yyyy. *

--> method 2* (works only when data fit an existing SPSS date format)

COMPUTE mydate=NUMBER(datestr,ADATE10). FORMATS mydate(ADATE10). VARIABLE WIDTH mydate(10). /* The purpose of this line is to display all 4 digits of the year in the data editor */. EXECUTE.

On Dec 20, 2007 12:33 PM, Raffe, Sydelle, SSA <DRaffe@acgov.org> wrote:

> I have string vars in the format 08/31/2007. How can I use syntax to > convert them to date vars? Thanks. > > Sydelle Raffe, Alameda County Social Services Agency > Information Services Division, Office of Data Management > e:mail: draffe@acgov.org > phone: 510-271-9174 fax: 510-271-9107 > If you have a request for information, please submit an ODM request form > at: > https://alamedasocialservices.org/staff/support_services/statistics_and_reports/odm/index.cfm > > To manage your subscription to SPSSX-L, send a message to > LISTSERV@LISTSERV.UGA.EDU (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@LISTSERV.UGA.EDU (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@LISTSERV.UGA.EDU (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


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