Problem Note 68731: An IF statement behaves differently and produces different results, based on whether variables are in an array or not
The IF statements in the following code example produce different results, based on whether the variables are in an array or not.
data test;
array a (2) a1 a2;
a1 = 1;
a2 = 0;
b = 1;
put 'ARRAY access : ' @;
if b and (a(1) or (a(2) 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;
/* log results */
ARRAY access : FALSE
Direct access : TRUE
A workaround is to reverse the order of the variables in the IF statement, as shown here:
put 'WORKAROUND : ' @;
if b and (a(2) or (a(1) or 0)) then put 'TRUE';else put 'FALSE';
The Output tab shows the full example code, with the workaround, and the log output from each of the three IF statements.
Click the Hot Fix tab in this note to access the hot fix for this issue.
The hot fix is for the SAS® 9.4M7 (TS1M7) release.
Operating System and Release Information
SAS System | Base SAS | Windows 7 Ultimate x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Windows 7 Ultimate 32 bit | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Windows 7 Professional x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Windows 7 Professional 32 bit | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Windows 7 Home Premium x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Windows 7 Home Premium 32 bit | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Windows 7 Enterprise x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Windows 7 Enterprise 32 bit | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows Server 2016 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows Server 2012 Std | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows Server 2012 R2 Std | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows Server 2012 R2 Datacenter | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows Server 2012 Datacenter | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows Server 2008 for x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows Server 2008 R2 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows Server 2008 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows 10 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows 8.1 Pro x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows 8.1 Pro 32-bit | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows 8.1 Enterprise x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows 8.1 Enterprise 32-bit | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows 8 Pro x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows 8 Pro 32-bit | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows 8 Enterprise x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft Windows 8 Enterprise 32-bit | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Microsoft® Windows® for x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
z/OS 64-bit | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
z/OS | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
64-bit Enabled AIX | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
64-bit Enabled Solaris | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
HP-UX IPF | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Linux for x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
Solaris for x64 | 9.4_M5 | 9.4_M8 | 9.4 TS1M5 | 9.4 TS1M8 |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
364 data test;
365 array a (2) a1 a2;
366 a1 = 1;
367 a2 = 0;
368 b = 1;
369 put 'ARRAY access : ' @;
370 if b and (a(1) or (a(2) or 0)) then put 'TRUE'; else put 'FALSE';
371 put 'Direct access : ' @;
372 if b and (a1 or (a2 or 0)) then put 'TRUE'; else put 'FALSE';
373 /* The workaround code follows */
374 put 'WORKAROUND : ' @;
375 if b and (a(2) or (a(1) or 0)) then put 'TRUE'; else put 'FALSE';
376 run;
ARRAY access : FALSE
Direct access : TRUE
WORKAROUND : TRUE
Type: | Problem Note |
Priority: | high |
Topic: | SAS Reference ==> Statements ==> Control ==> IF-THEN/ELSE
|
Date Modified: | 2022-01-11 16:45:17 |
Date Created: | 2022-01-03 09:01:57 |