1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
* Hi Raynald ... I've scoured your website, your SPSS Programming and Data Management
* book, and several users groups to find an example that solves this problem, but come
* up empty each place.  I just want to find whether or not each word in a list exists
* in a particular string variable in my data set.  I've been trying variations all
* day, but can't crack this seemingly simple problem.  Any ideas?

* Code by raynald@spsstools.net 2006 02 16.

NEW FILE.
DATA LIST / TESTVAR (A50).
BEGIN DATA
THIS IS A TEST CASE
THIS TESTS NOTHING THIS
END DATA.

DEFINE !findstr (!POS !CMDEND).
COMPUTE foundall=1.
  !DO !j !IN (!1).
  !LET !tempstr = !QUOTE(!j).
    IF INDEX(TESTVAR,!tempstr)=0 foundall=0.  
  !DOEND.
  EXECUTE.
!ENDDEFINE.

!findstr THIS TESTS NOTHING .