TotorosForest
TotorosForest

Reputation: 43

Problem with TIME variable values in SPSS

I need your suggestions how i can convert my time variable (Time_A, string format) into numeric format. The values are entered as follows: hmm or hhmm.

Please give suggestions, how to solve this problem. Regards.

When i use time and date function in SPSS, hhmm values convert good, however nothing happens with hmm values.

Upvotes: 2

Views: 273

Answers (2)

Anonymoose
Anonymoose

Reputation: 141

@eli-k has answered with a good explanation.

Another solution would be:

compute Time_A_num = NUMBER(RIGHT("0" + Time_A, 4), F4).

as it achieves the same result in fewer steps. It also creates a new variable, which avoids modifying the original data and allows for comparison with the original variable if necessary.

Upvotes: 1

eli-k
eli-k

Reputation: 11360

The problem is SPSS expects the first two characters to represent hours, and when the hour is less then 10 there is only one charachter. The solution is to add the missing character, which in these cases should be "0". So do the following before running the date-time transformations:

compute Time_A=char.lpad(Time_A, 4, "0").

This will turn your 3 digit strings into 4 digit strings that begin with "0".

Upvotes: 1

Related Questions