Hello
I want to ask if option1 and option2 are doing same or there is a difference?
Thanks
/***option1***/
IF x=5 OR (X=2 AND W=3) OR (X=2 AND W=8) AND Z=9 then Ind=1;
/***option2***/
IF (x=5 OR (X=2 AND W=3) OR (X=2 AND W=8)) AND Z=9 then Ind=1;
May anyone explain the calculation of Ind_a
I don't understand how it works,
why X=5 W=100 Z=90 get ind_a=1??
Data ttt;
input x w z;
cards;
5 100 9
5 100 90
8 90 9
;
Run;
Data wanted;
set ttt;
IF x=5 OR (X=2 AND W=3) OR (X=2 AND W=8) AND Z=9 then Ind_a=1;
IF (x=5 OR (X=2 AND W=3) OR (X=2 AND W=8)) AND Z=9 then Ind_b=1;
Run;
As already mentioned, AND is evaluated first, so this:
(X=2 AND W=8) AND Z=9
is calculated first; it is equivalent to
X=2 AND W=8 AND Z=9
all three conditions need to be satisfied for this part to become true. In your data, this is never the case.
Similarly, the other AND is evaluated (the brackets are not necessary, but they help in keeping the code clear).
Then come the ORs, and since X=5 is satisfied in the first two observations, the whole condition will become true.
In more readable form, your condition is this:
if
x=5
or (
X=2 and W=3
)
or (
X=2 and W=8 and Z=9
)
then Ind_a=1;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.