I have five string variables. I want to search
for a couple of specific keywords within the five variables.
For example I have
ID v1 v2 v3 v4 v5
1 text house
2 ext
3 tower
Now I want to search for some keywords like
ext ex=> this sould be defined as 'text'
hous ous => this sould be defined as 'house'
tow wer=> this sould be defined as 'tower'.
For each of the keywords a new variable should be created with 1
quoted and 0 not quoted.
The result should look like this:
ID text house tower
1 1 1 0
2 1 0 0
3 0 0 1
I found some macro:
define FINDEN (!pos !charend ('/') / !pos !tokens (1)
/ var=!tokens (1)).
!do !i !in (!1).
if (index(upcase (!v1), (!quote(!upcase(!i)))) ne 0)
text= (!quote (!2)).
if (index(upcase (!v2), (!quote(!upcase(!i)))) ne 0)
text= (!quote (!2)).
if (index(upcase (!v3), (!quote(!upcase(!i)))) ne 0)
text= (!quote (!2)).
if (index(upcase (!v4), (!quote(!upcase(!i)))) ne 0)
text= (!quote (!2)).
if (index(upcase (!v5), (!quote(!upcase(!i)))) ne 0)
text= (!quote (!2)).
!doend
exe.
!enddefine.
FINDEN ext ex / 1.
exe.
This works well, but the problem is that I only got one new variable
called 'text' .
How can I change this macro so that it searches through all five
variables for all of my keywords and creates new variables? So if
someone says ex there sould be '1' in one variable called 'text' and
if he says tow there should be a '1' in a variable called tower?
Any help is much aprreciated :D
I don't have SPSS on this computer, so the following is untested, but I
think it should work.
numeric text house tower (f1.0). /* the flag variables.
recode text to tower (else=0). /* initialize to zero.
vector haystack = v1 to v5. /* the original string variables.
do repeat
needle = "ext" "ous" "tow" "wer" /
flag = text house tower tower .
- loop # = 1 to 5.
- if not flag flag = index(haystack(#),needle) GT 0.
- end loop if flag.
end repeat.
execute.
--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."