BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AndyGunn
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

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

Ksharp
Super User
Very Interesting. It seems ARRAY can't resolve itself and get it's value in CONDITION ,just a symbol refer to a variable.

data test;
array a{2} a1 a2 (1 0);
a1 = 1;
a2 = 0;
b = 1;
put 'ARRAY access : ' @;
if b and (a{1}=1 or (a{2}=1 or 0)) then put 'TRUE'; else put 'FALSE';
put 'Direct access : ' @;
if b and (a1 or (a2 or 0)) then put 'TRUE'; else put 'FALSE';
run;


ARRAY access : TRUE
Direct access : TRUE

novinosrin
Tourmaline | Level 20

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

 

AndyGunn
Fluorite | Level 6

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.

AndyGunn
Fluorite | Level 6

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

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
  • 6 replies
  • 1360 views
  • 2 likes
  • 5 in conversation