03-21-2017 06:42 PM
How can I evaluate a variable to create another if the if function does not allow the like operator?
For example is easy if var is numeric, like:
IF VAR1 = 0 THEN VAR2 = 'A';
But if I need to evaluate something inside string of characters how can it be?
IF VAR1 LIKE "%A%" THEN VAR2 = "CONTAINS LETTER A"
What operator can I replace to LIKE?
03-22-2017 11:07 AM
thank you Art, and do you know how can I do it like a evaluate a list?
I know this does not work but is only an example:
IF VAR1 IN ('%A%','%B%','%C%') THEN VAR2 = 'CONTAINS LETTERS A B or C'
If I use this works:
IF INDEX(VAR1,'A') THEN VAR2 = 'CONTAINS LETTERS A B or C'
IF INDEX(VAR1,'B') THEN VAR2 = 'CONTAINS LETTERS A B or C'
IF INDEX(VAR1,'C') THEN VAR2 = 'CONTAINS LETTERS A B or C'
But is it possible to simplify it?
I simplified like this:
IF INDEX(VAR1,'A') or INDEX(VAR1,'B') or INDEX(VAR1,'C') THEN VAR2 = 'CONTAINS LETTERS A B or C'
but is there another way tah you know more shorten? some like:
IF INDEX(VAR1,'A','B','C') THEN VAR2 = 'CONTAINS LETTERS A B or C'
03-21-2017 09:05 PM
alternatively we could try the perl regular expression like below
if prxmatch('m/[a]/i',VAR1) then VAR2="CONTAINS LETTER A";
03-22-2017 11:52 AM
the findc function allows you to both find if a string contains one or more of the variables in a list, as well as ignore case (if desired). e.g.:
informat string $23.;
input string &;
if findc(string, 'abc', "i") then
want='Contains A, B or C';
Microsoft Office Visio
Microsoft Office Word
Art, CEO, AnalystFinder.com
Need further help from the community? Please ask a new question.