Searching in String Variables

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

jrutledge
Posts: 2
Joined: Fri Jan 22, 2016 4:34 pm

Searching in String Variables

Postby jrutledge » Fri Jan 22, 2016 4:41 pm

Greetings Everyone,

I am looking through a string variable for various terms. The string variable is going to be in narrative form. Therefore, I need the code to look for a specific set of terms and ignore case. For example, if any of the following terms are present I want to create a flag variable 1 and 0 if these terms are not present.

CVD cardiovascular disease hypertension high blood pressure

I know the synatx for looking for each one of these individually, but is there a way to write one piece of code to look for all of these and ignore case?

I can do this easily in SAS, but my SAS license expired and I need to figure out how to do this in SPSS.

Any assistance would be greatly appreciated,

Jared
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Searching in String Variables

Postby GerineL » Mon Jan 25, 2016 2:31 pm

Look here: http://www.spss-tutorials.com/spss-index-function/

is this what you need?
jrutledge
Posts: 2
Joined: Fri Jan 22, 2016 4:34 pm

Re: Searching in String Variables

Postby jrutledge » Mon Jan 25, 2016 3:48 pm

Greetings,

Yes, that is what I have been using, but how to I string together several for example:

compute hep_c1=char.index(lower(cause), "hep c")>0.
compute hepatitis_c1=char.index(lower(cause), "hepatitis c")>0.
compute hepatitisc1=char.index(lower(cause), "hepatitisc")>0.
compute hvc1=char.index(lower(cause), "hvc")>0.

compute hcv2=char.index(lower(cause1), "hcv")>0.

compute hepc2=char.index(lower(cause1), "hepc")>0.


I have to run each one of these individually and then add them all together to look for the presence of any of these indicators. Is it possible to computer one variable that looks for hep C, hepatitis c, hepatitisc, hvc, hcv, or hepc.

For example:

compute hep_c=char.index(lower(cause), "hep c" "hepatitis c" "hepatitisc" "hvc" "hcv" "hepc')>0.

I want the above code to be able to look for any of the above versions and code 1 for any of the above.

Let me know,

Jared
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Searching in String Variables

Postby GerineL » Mon Feb 01, 2016 9:38 am

don't know, just try to mess around with it a bit, trial and error. Maybe use | (the "or" sign).

Who is online

Users browsing this forum: No registered users and 1 guest

cron