Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Expression evaluating to False but seems it should be True.

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 12-19-2020 06:52 PM
(582 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Open a track with Technical Support. This looks like a bug to me, and a rather serious one.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

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.