Flag Where Given String Contains Given Word - Problem

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

tessnorman
Posts: 1
Joined: Thu Feb 26, 2015 7:13 pm

Flag Where Given String Contains Given Word - Problem

Postby tessnorman » Thu Feb 26, 2015 8:17 pm

I am using a similar syntax to 'Flag cases where a given string variable contains a given word' from Raynald's SPSS Tools website. http://www.spsstools.net/

I have a string variable with text and I want to create a flag variable (binary variable) whenever the text string contains a word that has to do with "anger"


String variable:

I am angry
The tv show made me happy
I am happy
there is so much hate in the world

I use:

COMPUTE Flag = sum(INDEX(string,"angry"), INDEX(string,"mad"), INDEX(string,"hate"))>0


It works well except for one problem. It also flags strings that, for example, contain the characters "mad" within a word, like the word "made". So the string: "The tv show made me happy" will also get flagged. Any ideas of how to fix this? I tried to put spaces on either side of mad: " mad ", but it doesn't work.
Grateful for any input!

Who is online

Users browsing this forum: No registered users and 2 guests

cron