CHAR.INDEX not working at first position

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

jwkarr
Posts: 2
Joined: Mon Sep 19, 2011 9:59 pm

CHAR.INDEX not working at first position

Postby jwkarr » Fri Dec 05, 2014 10:55 pm

I've searched the forums and can't find much on this command, so here goes...

I'm trying to do something simple, namely record the position at which a certain substring (name) begins in a larger string (userid). So I use the following command:

COMPUTE NAMEPOS= CHAR.INDEX(userid,name).

Frustratingly, there are multiple times when the command does not seem to recognize matches, and they all seem to be related to the substring occurring at the very first position of the larger string. Occurrences later in the string are recognized. For example:

userid="johnsmith88", name="john", CHAR.INDEX(userid,name) = 0. (Incorrect)
userid="stephanieb222", name="stephanie", CHAR.INDEX(userid,name) = 0. (Incorrect)

But

userid="taylordan", name="dan", CHAR.INDEX(userid,name) = 7. (Correct)

Even weirder, if I use CONCAT to create a new first character, SPSS *still* doesn't recognize the substring!

COMPUTE userid= CONCAT("a",userid).

still gives...

userid="ajohnsmith", name="john", CHAR.INDEX(userid,name) = 0. (Incorrect)
userid="astephanieb222", name="stephanie", CHAR.INDEX(userid,name) = 0. (Incorrect)

This is crazy! Anyone got any ideas? I'm using v20.0.0.2 on Windows. (It doesn't look like there's a v20.0.0.3.)

James
KeithMurray
Posts: 16
Joined: Fri Feb 21, 2014 1:12 pm

Re: CHAR.INDEX not working at first position

Postby KeithMurray » Tue Dec 09, 2014 8:27 am

Hi James

I'm using version 20.0.0.

I've recorded "johnsmith88" as a cell value in VAR00001 and

COMPUTE weestring=CHAR.INDEX(VAR00001,"john").

returns the value 1 correctly.

Could your problem be a bug in your particular version?

Who is online

Users browsing this forum: No registered users and 1 guest

cron