IBM Support

IBM SPSS Statistics Using INDEX and SUBSTR as Search/Replace

Troubleshooting


Problem

I am using IBM SPSS Statistics for Windows. I have been sent a dataset where the embedded zeroes have been changed to blanks. I need to transform this field into a TIME variable. Is there any way to salvage this data?

Resolving The Problem

It is usually possible to use the SPSS transformation language to correct various data entry errors. The following illustrates the use of the INDEX and SUBSTR functions to perform a 'search and replace' operation.

* Sample data *.

DATA LIST / T 1-4 (A).
BEGIN DATA
8 5 (08:05)
1 5 (10:05)
1115 (11:15)
END DATA .

* Insert 0's where needed *.

LOOP.
COMPUTE #I=INDEX(T,' ').
IF #I>0 SUBSTR(T,#I,1)='0'.
END LOOP IF #I=0.

* Convert 4 character string to time and format it * .

COMPUTE TIME=NUMBER(CONCAT(SUBSTR(T,1,2),':',SUBSTR(T,3,2)),TIME5).
FORMAT TIME (TIME5).
LIST

[{"Product":{"code":"SSLVMB","label":"IBM SPSS Statistics"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Not Applicable","Platform":[{"code":"PF033","label":"Windows"}],"Version":"Not Applicable","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Historical Number

17174

Document Information

More support for:
IBM SPSS Statistics

Software version:
Not Applicable

Operating system(s):
Windows

Document number:
417727

Modified date:
16 April 2020

UID

swg21476146

Manage My Notification Subscriptions