Hi Nai,
Try the following commands:
COMPUTE new_time = TIME.HMS(NUMBER(SUBSTR(call_time,1,
INDEX(call_time,':')-1),F2),
NUMBER(SUBSTR(call_time,INDEX(call_time,':')+1),F2)).
EXE.
FORMATS new_time (TIME5).
I've embedded several functions within the COMPUTE statement to address the original string variable. I hope this helps.
John Norton
SPSS Inc.
-----Original Message-----
From: SPSSX(r) Discussion [mailto:
[hidden email]] On Behalf Of Nai Li
Sent: Wednesday, April 04, 2007 9:32 AM
To:
[hidden email]
Subject: Covert a string time variable into a numeric variable
Dear List,
I wonder if you know how I can covert a string time variable (named
call_time) formatted as hh:mm into a numeric variable named as calltim
(hh:mm)? I tried to run the following syntax, but it doesn't work. Can
some one point me in the right direction?
DATA LIST /call_time (a5).
BEGIN DATA
14:23
12: 34
23: 01
END DATA.
STRING #time(A5).
COMPUTE #time = CONCAT(SUBSTR(call_time,1,2),':',SUBSTR(call_time,3,2)).
COMPUTE Calltim = NUMBER(#time,TIME5).
FORMATS calltim (TIME5).
EXECUTE.
Many thanks in advance.
Nai