f



Contain function String

Hi, 

I have two variables - var1 and var2, each of them has a lot string values like - "There is a dog", "Cats are fun", "Where is my dog?" etc. 

I am trying to recode var1 and var2 to either the string value containing "cats" becomes 1, or string value containing "dogs" becomes 2.

Could you advise me some useful code to do that?
0
kaplan
12/21/2016 4:46:25 PM
comp.soft-sys.stat.spss 5679 articles. 0 followers. Post Follow

2 Replies
549 Views

Similar Articles

[PageSpeed] 43

Look at CHAR.INDEX, and IF.

IF CHAR.INDEX(UPCASE(var),"CAT") GT 0 newvar=1.
IF CHAR.INDEX(UPCASE(var),"DOG") GT 0 newvar=2.
etc...


On Wednesday, December 21, 2016 at 11:46:27 AM UTC-5, kaplan...@gmail.com wrote:
> Hi, 
> 
> I have two variables - var1 and var2, each of them has a lot string values like - "There is a dog", "Cats are fun", "Where is my dog?" etc. 
> 
> I am trying to recode var1 and var2 to either the string value containing "cats" becomes 1, or string value containing "dogs" becomes 2.
> 
> Could you advise me some useful code to do that?

0
David
12/21/2016 4:57:42 PM
"The dog is being eaten by the cat".
Maybe you need to think a bit more?
---
On Wednesday, December 21, 2016 at 11:57:47 AM UTC-5, David Marso wrote:
> Look at CHAR.INDEX, and IF.
> 
> IF CHAR.INDEX(UPCASE(var),"CAT") GT 0 newvar=1.
> IF CHAR.INDEX(UPCASE(var),"DOG") GT 0 newvar=2.
> etc...
> 
> 
> On Wednesday, December 21, 2016 at 11:46:27 AM UTC-5, kaplan...@gmail.com wrote:
> > Hi, 
> > 
> > I have two variables - var1 and var2, each of them has a lot string values like - "There is a dog", "Cats are fun", "Where is my dog?" etc. 
> > 
> > I am trying to recode var1 and var2 to either the string value containing "cats" becomes 1, or string value containing "dogs" becomes 2.
> > 
> > Could you advise me some useful code to do that?

0
David
12/21/2016 6:23:43 PM
Reply: