|
Hi Ari,
I've added a new entry as well 145 for 01:45 just in case you have had any entries were the leading 0 was dropped. Most of the syntax comes from the Date/Time wizard (v13+), but to make it all work you need to reformat your original string so there is the delimiter between the hours and minutes, so SPSS can recognise the string as the time format hh:mm. You can delete newTime afterwards because you don't need it (DEL VAR newTime.) or have it as a scratch variable so it doesn't exist in the data editor after the execute statement (add # to the variable name throughout the syntax).
Rgds,
Antro.
data list / assaulttime (A4).
begin data
0145
0728
1334
145
end data.
STRING newTime (A5).
DO IF LENGTH(RTRIM(assaulttime)) = 4.
+ COMPUTE newTime = CONCAT(SUBSTR(assaulttime ,1,2), ":", SUBSTR(assaulttime,3)).
ELSE IF LENGTH(RTRIM(assaulttime)) = 3.
+ COMPUTE newTime = CONCAT(SUBSTR(assaulttime ,1,1), ":", SUBSTR(assaulttime,2)).
END IF.
COMPUTE assaulttime2 = number(newTime , TIME5).
VARIABLE LABEL assaulttime2 .
VARIABLE LEVEL assaulttime2 (SCALE).
FORMATS assaulttime2 (TIME5).
VARIABLE WIDTH assaulttime2 (5).
EXE.
|