John Spirawk
John Spirawk

Reputation: 31

Syntax if variable includes a specific string of text

I was wondering if there was a syntax to select all account names that include a certain string of text.

For example, if I have a SPSS file that has 3 million account names, I'd want to look at only the account names that have a / TKS at the end. The account name could like like Stack Overflow / TKS.

Upvotes: 3

Views: 10072

Answers (2)

horace_vr
horace_vr

Reputation: 3166

The solution eli-k provided checks if / TKS is inside the account_name, at any position. If you want to check if the "/ TKS" text is at the end of your account_name, you need a slightly changed syntax:

compute containsTKS=0.
if char.index(account_name,"/ TKS")=char.len(rtrim(account_name))-5 containsTKS=1.
execute.

Then, as eli-k mentioned, "You can then use containsTKS to filter or select cases."

Upvotes: 1

eli-k
eli-k

Reputation: 11310

You can use char.index to check whether a string includes a specific substring. So for example:

compute containsTKS=0.
if char.index(account_name,"/ TKS")>0 containsTKS=1.
execute.

You can then use containsTKS to filter or select cases.

Upvotes: 2

Related Questions