3

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.

eli-k
  • 10,898
  • 11
  • 40
  • 44
John Spirawk
  • 31
  • 1
  • 2

2 Answers2

2

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.

eli-k
  • 10,898
  • 11
  • 40
  • 44
1

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."

horace_vr
  • 3,026
  • 6
  • 26
  • 48