Page 1 of 1

Transformed variable - if source contains

Posted: Wed Nov 27, 2019 11:45 am
by coce
Hi,
I'd like to recode some variables so if a source contains a certain text I'd like to use a number for it.

Example:

Source
id1: Dog, Cat, Mouse
id2: Dog
id3: Dog, Cat
id4: Dog, Mouse

New variable 1:
If source contains Dog use 1
Then with this all the ids would use 1.

Right now I can only see the Equal to operator but that'll only work for id2.

I assume with a function it's doable, but I'm not so familiar with functions. Any ideas?

Thanks!

Re: Transformed variable - if source contains

Posted: Thu Nov 28, 2019 1:12 am
by jonathon
hmm,

we've not encountered this sort of use case before. perhaps we need to consider it.

you'll need to use computed variables for this:

IF(CONTAINS('Dog', variableName), 1, IF(CONTAINS('Cat', variableName), 2, ... ))

jonathon

Re: Transformed variable - if source contains

Posted: Thu Nov 28, 2019 10:33 am
by coce
Thanks jonathon!

Mhmm, maybe I'm doing something wrong, but it doesn't seem to work. i use Version 1.0.8.0 on a MacOS Catalina.

https://i.imgur.com/Mq3Do56.png

Re: Transformed variable - if source contains

Posted: Thu Nov 28, 2019 11:41 am
by jonathon
oh yeah, you'll need a more recent version.

jonathon

Re: Transformed variable - if source contains

Posted: Thu Nov 28, 2019 12:45 pm
by coce
Pefect, thank you so much!

Re: Transformed variable - if source contains

Posted: Thu Oct 06, 2022 9:53 pm
by SoZ
jonathon wrote:hmm,

we've not encountered this sort of use case before. perhaps we need to consider it.

you'll need to use computed variables for this:

IF(CONTAINS('Dog', variableName), 1, IF(CONTAINS('Cat', variableName), 2, ... ))

jonathon
Hi Jonathon, how many if can I concatenate in the same expression?

Re: Transformed variable - if source contains

Posted: Wed Oct 12, 2022 11:05 pm
by jonathon
i don't think there's a limit

jonathon

Re: Transformed variable - if source contains

Posted: Fri Jan 27, 2023 8:21 am
by Wake
jonathon wrote: Thu Nov 28, 2019 1:12 am we've not encountered this sort of use case before. perhaps we need to consider it.
I've just installed version 2.3.21 and come across the same issue. I'm trying to transform job titles into whether they are technical or not. I'd just switched to using COMPUTE but I thought I'd Google before going any further.