DATA Step, Macro, Functions and more

IF...THEN... statement and logic expression

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

IF...THEN... statement and logic expression

Hi All,

 

I ran into a problem in which I need to write a long logic expression: A01=1 OR A02=1 OR A03=1 OR A04=1 OR... A15=1 then TF=1;

 

Not sure if there is an easy and quick way to write the code? Say, IF any of (A01--A15) =1 then TF=1?

 

Thanks


Accepted Solutions
Solution
‎08-22-2016 01:11 PM
Super User
Posts: 5,509

Re: IF...THEN... statement and logic expression

If you create an array holding the variables, there are two methods.  The array:

 

array alist {15} a01-a15;

 

Then you could search with:

 

if whichn(1, of alist{*}) then TF=1;

 

Surprisingly, this method also works (once the array is defined):

 

if 1 in alist then TF=1;

View solution in original post


All Replies
Solution
‎08-22-2016 01:11 PM
Super User
Posts: 5,509

Re: IF...THEN... statement and logic expression

If you create an array holding the variables, there are two methods.  The array:

 

array alist {15} a01-a15;

 

Then you could search with:

 

if whichn(1, of alist{*}) then TF=1;

 

Surprisingly, this method also works (once the array is defined):

 

if 1 in alist then TF=1;

Contributor
Posts: 40

Re: IF...THEN... statement and logic expression

Posted in reply to Astounding
Thanks so much!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 324 views
  • 2 likes
  • 2 in conversation