Any idea why HIT2 is not showing in the log from this code?:
data;
array a (2) a1 a2;
a1 = 1;
a2 = 0;
b = 1;
if b and (a(1) or a(2) or 0) then put 'HIT1';
if b and (a(1) or (a(2) or 0)) then put 'HIT2';
if b and (1 or (0 or 0)) then put 'HIT3';
put _all_;
run;
HIT1
HIT3
a1=1 a2=0 b=1 _ERROR_=0 _N_=1
Open a ticket with SAS support. Send them this program:
68 data test; 69 array a (2) a1 a2; 70 a1 = 1; 71 a2 = 0; 72 b = 1; 73 put 'ARRAY access : ' @; 74 if b and (a(1) or (a(2) or 0)) then put 'TRUE'; else put 'FALSE'; 75 put 'Direct access : ' @; 76 if b and (a1 or (a2 or 0)) then put 'TRUE'; else put 'FALSE'; 77 run; ARRAY access : FALSE Direct access : TRUE NOTE: The data set WORK.TEST has 1 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
Open a ticket with SAS support. Send them this program:
68 data test; 69 array a (2) a1 a2; 70 a1 = 1; 71 a2 = 0; 72 b = 1; 73 put 'ARRAY access : ' @; 74 if b and (a(1) or (a(2) or 0)) then put 'TRUE'; else put 'FALSE'; 75 put 'Direct access : ' @; 76 if b and (a1 or (a2 or 0)) then put 'TRUE'; else put 'FALSE'; 77 run; ARRAY access : FALSE Direct access : TRUE NOTE: The data set WORK.TEST has 1 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
Open a track with Technical Support. This looks like a bug to me, and a rather serious one.
Hi @AndyGunn I very very vaguely recall reading this problem illustrated by either Guru's @hashman or @data_null__ the 2 whom I closely follow suggesting to explicitly assign the value when it comes to array references- a(1)=1 , allternatively ^^a(1)/*for boolean*/
if b and (a(1)=1 or (a(2) or 0)) then put 'HIT2';
if b and (^^a(1) or (a(2) or 0)) then put 'HIT2';
However at 7:30pm with a couple of pints I can't remember which one that is. Though my eyes are hazy, I am certain it's one of the above Guru's who once even suggested me to not to play with production codes like I used to otherwise. So -
141 data;
142 array a (2) a1 a2;
143 a1 = 1;
144 a2 = 0;
145 b = 1;
146 if b and (a(1) or a(2) or 0) then put 'HIT1';
147 if b and (a(1)=1 or (a(2) or 0)) then put 'HIT2';
148 if b and (1 or (0 or 0)) then put 'HIT3';
149 put _all_;
150 run;
HIT1
HIT2
HIT3
a1=1 a2=0 b=1 _ERROR_=0 _N_=1
NOTE: The data set WORK.DATA11 has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
Thanks much for the response(s). I believe this is my first time ever posting here. Rare to find problems like this - this one was painful. But, I had hope wise people would help. I will open a ticket with SAS.
Hello novinosrin, I did use the '=1' shown in your example code to get my job working for now. Was cleaner than things I was thinking of. Have not heard back from SAS yet. Track 7613246087. Thanks, Andy
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.