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

Convert a STRING "DD.MM.AAAA HH:MM:SS" to DATETIME format

870 views
Skip to first unread message

Statistician_Brazil

unread,
Nov 8, 2006, 12:55:44 PM11/8/06
to
Dear friends

I have a STRING variable for example: 22.10.1990 12:20:31 and I
want convert this
for a DATE format in SPSS using syntax. Do you know a soluction?

Thanks for all responses.

Carlos Renato
Statistician

the.lae...@gmail.com

unread,
Nov 8, 2006, 2:35:37 PM11/8/06
to
Try going to the "variable view" tag.

- Identify the row where your string variable is.
- Under the column "type", click and open a menu
- Check "Date"
- In the selection list, choose dd-mmm-yyyy hh:mm:ss

That should do the job.

Bruce Weaver

unread,
Nov 8, 2006, 4:40:48 PM11/8/06
to

Although it does not have exactly the situation you describe, this file
shows how to convert string variables to date variables. It should give
you some good ideas.

www.angelfire.com/wv/bwhomedir/spss/importing_excel_dates.txt


--
Bruce Weaver
bwe...@lakeheadu.ca
www.angelfire.com/wv/bwhomedir

Statistician_Brazil

unread,
Nov 9, 2006, 6:51:59 AM11/9/06
to
Dear friend

I want to solve this using syntax.

Thanks for response.

Carlos Renato

the.lae...@gmail.com escreveu:

JKPeck

unread,
Nov 10, 2006, 8:23:41 AM11/10/06
to
The basic mechanism is to use the NUMBER function on this variable and
give it a format that describes the string. What you have is close to
the DATETIME format, but that takes a three-letter month instead of a
number. So break your string into date and time portions (via
SUBSTR(), and convert the date part and time parts separately. Then
just add them together.

The Bonus Pack modules, if you have SPSS 15 with programmability
installed, include a very general date or date/time pattern language
that can be used to convert almost anything.

Function strtodatetime(value, pattern) takes a string and a pattern and
produces an SPSS date/time variable. In this case, the pattern would
be something like this:
"%d.%m%Y %I:%M%S" if your hours are 12-hour or the %I would be %H if in
24 hour.
In the former case, you could also include %p to indicate am/pm.

You would use this function, which is in the extendedTransforms module
with the trans module to have it iterate over all the cases.

The Bonus Pack will be available on SPSS Developer Central
(www.spss.com/devcentral) at the end of November.

HTH,
Jon Peck
SPSS

0 new messages