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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.