## IF statement logic

Solved
Frequent Contributor
Posts: 81

# IF statement logic

[ Edited ]

Hi,

Have

var1 var2 var3 var4

1       2      2      4

1       3      3      3

1       2      2      0

1      5       5      5

want if var1 =1 and value of var2 , var3 or var4 is either 2 or 3 then flag =1 else 0.

want

var1 var2 var3 var4 flag

1       2      2      4      1

1       3      3      3       1

1       2      2      0        1

1      5       5      5        0

thanks

Accepted Solutions
Solution
‎07-12-2016 08:07 PM
Super User
Posts: 23,735

## Re: iF STATEMENT

``````If var1=1 and (var2 in (2 3) or var3 in (2 3) or var4 in (2 3)) then flag=1;
Else flag=0;``````

All Replies
Solution
‎07-12-2016 08:07 PM
Super User
Posts: 23,735

## Re: iF STATEMENT

``````If var1=1 and (var2 in (2 3) or var3 in (2 3) or var4 in (2 3)) then flag=1;
Else flag=0;``````

Frequent Contributor
Posts: 81

## Re: iF STATEMENT

[ Edited ]

Thank you am also looking for an easy if statement

have

var1  var2  var3  var4  flag (want)

a        b        b      a        0

a       a                 a        1

a                                    1

if the value (could be any) but in above eg its "a" of var1 matches with var1 2 or 3 then flag 1 else 0

All vlaues should match var1 or be equal to var1

Thanks

Super User
Posts: 23,735

## Re: iF STATEMENT

You should start a new thread for a new question.

'Easiest' depends on your programming skills.

For something like this your best of looping through all values.

array vars(3) var2-var4;

Flag=0;

do i =1 to dim(vars);

if  vars(I) ne var1 then flag=1;

end;

Another option

array vars(3) var2-var4;

flag=0;

if catt(of vars(*)) ne repeat(var1, n(of vars(*))) then flag=1;

Super User
Posts: 13,553

## Re: IF statement logic

Here is an alternate approach to consider if you have more variables to search but still have a smallish number of values.

``````array t var2-var4;
flag = (var1=1 and (whichn(2, of t(*))>0 or whichn(3, of t(*))>0));``````

if you have 15 variables to search in for example then you just add them to the Array definition.

If you want to search for character values use WhichC instead of WhichN.

☑ This topic is solved.