Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Search for multiple keywords within a string in SPSS syntax

7,861 views
Skip to first unread message
Message has been deleted

Ben Pfaff

unread,
Jul 21, 2010, 12:58:42 AM7/21/10
to
theglazeb <theg...@gmail.com> writes:

> I have a string variable that contains a lot of text. I want to search
> for a couple of specific keywords within the text, and then if it
> finds any of them, it flags the case by returning a 1.
>
> The closest I can come to this is as follows:
>
> COMPUTE flag=INDEX(UPCASE(VAR1),"ABCD")>0.
>
> VAR1 is the string variable, and ABCD is the keyword to search for.
>
> This works correctly for one possibility, "ABCD".
>
> The problem is, I want it to search for EITHER "ABCD", OR "Dee Eee Fff
> Ggg". If it finds either one of those options, then I want it to
> return a 1. There could be two or more keywords to search for, such as
> "ABCD" OR "Dee Eee Fff Ggg" OR "HIJK". Note that the text will all be
> in different cases, so the "ABCD" may in fact be written as "abcd".
>
> I can't seem to stack the commands:
> COMPUTE flag=INDEX(UPCASE(VAR1),"ABCD")>0.
> COMPUTE flag=INDEX(UPCASE(VAR1),"DEE EEE FFF GGG")>0.

COMPUTE #flag1=INDEX(UPCASE(VAR1),"ABCD")>0.
COMPUTE #flag2=INDEX(UPCASE(VAR1),"DEE EEE FFF GGG")>0.
COMPUTE flag = #flag1 OR #flag2.
--
"Writing is easy.
All you do is sit in front of a typewriter and open a vein."
--Walter Smith

fred....@lsc.gov.uk

unread,
Jul 21, 2010, 3:17:56 AM7/21/10
to
Or

COMPUTE flag=sum(INDEX(UPCASE(VAR1),"ABCD"), INDEX(UPCASE(VAR1),"DEE
EEE FFF GGG"))>0.

On Jul 21, 5:58 am, b...@cs.stanford.edu (Ben Pfaff) wrote:

> --Walter Smith- Hide quoted text -
>
> - Show quoted text -

Message has been deleted

ankemu...@gmail.com

unread,
Feb 22, 2018, 2:44:14 PM2/22/18
to
Hello,

I'm also looking for some keywords in a string. I used the following syntax:
COMPUTE attitude_afstand = INDEX(UPCASE(Bord_afstand_3_t),"OPLETTEN")>0.

It doesn't work however. The variable 'attitude_afstand' only contains dots (missing values). I don't understand why.
Can you help me please?

Kylie Lange

unread,
Feb 22, 2018, 6:12:21 PM2/22/18
to
Have you executed/run the command?

Add the following after the COMPUTE statement:

EXECUTE.

Bruce Weaver

unread,
Feb 23, 2018, 9:03:36 AM2/23/18
to
If Kylie's guess is correct, you'll see "Transformations pending" in an information area in the lower right corner of the data editor window.

Also, rather than adding an EXECUTE command, you could add any command that causes the data to be read. It seems to me that you might want to inspect a frequency table for the newly computed variable, for example. So you could use this in place of EXECUTE:

FORMATS attitude_afstand (F1).
FREQUENCIES attitude_afstand.

0 new messages