Re: Converting time stored as a string variable to a date variable (TIME5)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Converting time stored as a string variable to a date variable (TIME5)

Edward Boadi
Dear Ariel ,

"You cannot change the fundamental type of a variable through syntax.
The Data Editor has always had a sneaky non-syntax way of doing this,
but since changing the type (including the width of a string)
has broad implications, it doesn't work with syntax.  (Maybe someday)" ----by Jon Peck (SPSS) .



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of
ariel barak
Sent: Tuesday, September 19, 2006 5:05 PM
To: [hidden email]
Subject: Converting time stored as a string variable to a date variable
(TIME5)


Hello SPSS members,

I have time data (military) with some missing values in the format below
stored as a string variable. I have written the syntax below which converts
the data from 0145 into 01:45 properly. I can easily convert the String
variable to the proper TIME5 date format via the GUI but have run into
nothing but trouble trying to do this via syntax. I'm sure there is a very
simple solution.

Thanks for your help.

-Ari


data list / assaulttime (A4).
begin data
0145
0728

1334
end data.

STRING hour (A2).
STRING minute (A2).
COMPUTE hour = SUBSTR(assaulttime, 1, 2).
COMPUTE minute = SUBSTR(assaulttime, 3, 2).
EXE.

STRING assaulttime2 (A5).
COMPUTE assaulttime2 = CONCAT(hour, ':', minute).
IF assaulttime2 = '  :' assaulttime2 = ''.
EXE.