Not applicable
Posts: 1

Easier way of writing Multiple combinations?

Hi,

I need to write code to track variables and display whether they get triggered or not.

For e.g. I have 5 variables (A1 to A5) which have different values.

Some of the code that I have been writing is as follows:

if A1>0 and A2 >0 and a3>0 and a4>0 and A5>0 then test="All A1-A5";

else if A1>0 and A2 >0 and a3>0 and a4>0 and A5=0 then test="A1-A4" ;

else.....

You get the picture - there are numerous combinations that can be coded.

Is there an easier way of coding this?

Any help would be appreciated.

Thanks

yash

Super User
Posts: 6,785

Re: Easier way of writing Multiple combinations?

This is shorter, although the format of the output is a little different:

test = put(A1 > 0, 1.) || put(A2 > 0, 1.) || put(A3 > 0, 1.) || put(A4 > 0, 1.) || put(A5 > 0, 1.);

Besides having a different format, it doesn't check for missing values vs. 0.  But it may be good enough regardless.

Good luck.

Super User
Posts: 9,599

Re: Easier way of writing Multiple combinations?

Hi,

Well, you would be looking at array processing.  Some questions though, what happens if A1-A3 > 0, and A6-A7?  So a basic example of arrays:

data want;

set have;

array a{*} 8.;

do i=1 to dim(a);

if a{i}>0 then ...;

end;

run;

Super User
Posts: 13,583

Re: Easier way of writing Multiple combinations?

if min(of A1-A5) > 0 then test="All A1-A5";

else if min(of A1-A4)>0 and A5=0 then test="A1-A4";

/* your pattern isn't necessarily obvious but perhaps*/

else if min(of A1-A3)>0 and max(A4, A5)=0 then test="A1-A3";

But if you get to A1, A3 and A5 >0 and A2, A4=0 you're not going to find much simplification.

Discussion stats
• 3 replies
• 253 views
• 1 like
• 4 in conversation