BookmarkSubscribeRSS Feed
YashSingh
Calcite | Level 5

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

3 REPLIES 3
Astounding
PROC Star

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

ballardw
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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