Flag string variable that contains a given number

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

abc2009
Posts: 7
Joined: Wed Feb 17, 2010 10:12 am

Flag string variable that contains a given number

Postby abc2009 » Thu Jan 17, 2013 2:40 pm

Dear all,

Please, help me with the syntax that I cannot improve myself.

I need to identify string variables, that contain certain number (let's say 410).

The problem is that this string variable can contain such data as "V410", "4107", "57410", etc.

I need to identify only those strings that starts from "410" and does not matter what goes latter. There should be, however, nothing in front. Thus, among "V410", "4107", "57410" only "4107" should be selected.

I tried to use the following syntax, but it identifies all strings that contian "410":

COMPUTE flag=INDEX(string,'410')>0.

Thank you in advance!

Regards,
Grigory.
JonPedersen
Posts: 118
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: Flag string variable that contains a given number

Postby JonPedersen » Sun Jan 20, 2013 6:54 pm

Hi,
Assuming that the string always starts with what you are looking for then
compute flag=CHAR.SUBSTR(stringvar,1,3)='410'
should do the trick.
Alternatively, a slight modification of your code would be
compute flag=CHAR.INDEX(stringvar,'410')=1
since index returns the position of the first character of the match.
(the difference between those string functions prefixed with "CHAR." and the non prefixed ones is that the latter do not handle unicode.)
best
jon
abc2009
Posts: 7
Joined: Wed Feb 17, 2010 10:12 am

Re: Flag string variable that contains a given number

Postby abc2009 » Thu Jan 24, 2013 3:26 pm

It works! Thank you a lot!

Who is online

Users browsing this forum: No registered users and 1 guest

cron