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
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.
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;
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.