Usage Note 51054: A WHERE clause that uses the NOT operator returns different results in PROC SQL than it does in SAS® DATA step and Base SAS® procedures
The WHERE clause in an SQL query and the WHERE statement in DATA step and Base SAS procedures use different languages.
They both use the word WHERE, and many but not all expressions use the same syntax. However, operator precedence in the SQL WHERE clause follows the SQL language definition, and in the Base SAS WHERE statement, the precedence follows SAS language conventions.
For more information, see the "Order of Evaluation in Compound Expressions for SAS Operators in Expressions" section in the SAS Language Reference Concepts, Fifth Edition® 9.4.
The SQL query treats NOT as a logical operator, similar to AND and OR. The expression syntax of Base SAS, which was defined before that of SQL, treats NOT as a mathematical operator. Click the Full Code tab to see an example that illustrate the difference in results returned from PROC SQL versus Base SAS with the NOT operator in the WHERE statement.
Operating System and Release Information
SAS System | Base SAS | z/OS | | |
Z64 | | |
OpenVMS VAX | | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | | |
Microsoft Windows XP 64-bit Edition | | |
Microsoft® Windows® for x64 | | |
OS/2 | | |
Microsoft Windows 8 Enterprise 32-bit | | |
Microsoft Windows 8 Enterprise x64 | | |
Microsoft Windows 8 Pro 32-bit | | |
Microsoft Windows 8 Pro x64 | | |
Microsoft Windows 95/98 | | |
Microsoft Windows 2000 Advanced Server | | |
Microsoft Windows 2000 Datacenter Server | | |
Microsoft Windows 2000 Server | | |
Microsoft Windows 2000 Professional | | |
Microsoft Windows NT Workstation | | |
Microsoft Windows Server 2003 Datacenter Edition | | |
Microsoft Windows Server 2003 Enterprise Edition | | |
Microsoft Windows Server 2003 Standard Edition | | |
Microsoft Windows Server 2003 for x64 | | |
Microsoft Windows Server 2008 | | |
Microsoft Windows Server 2008 R2 | | |
Microsoft Windows Server 2008 for x64 | | |
Microsoft Windows Server 2012 Datacenter | | |
Microsoft Windows Server 2012 Std | | |
Microsoft Windows XP Professional | | |
Windows 7 Enterprise 32 bit | | |
Windows 7 Enterprise x64 | | |
Windows 7 Home Premium 32 bit | | |
Windows 7 Home Premium x64 | | |
Windows 7 Professional 32 bit | | |
Windows 7 Professional x64 | | |
Windows 7 Ultimate 32 bit | | |
Windows 7 Ultimate x64 | | |
Windows Millennium Edition (Me) | | |
Windows Vista | | |
Windows Vista for x64 | | |
64-bit Enabled AIX | | |
64-bit Enabled HP-UX | | |
64-bit Enabled Solaris | | |
ABI+ for Intel Architecture | | |
AIX | | |
HP-UX | | |
HP-UX IPF | | |
IRIX | | |
Linux | | |
Linux for x64 | | |
Linux on Itanium | | |
OpenVMS Alpha | | |
OpenVMS on HP Integrity | | |
Solaris | | |
Solaris for x64 | | |
Tru64 UNIX | | |
*
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.
The following code will illustrate the operator precedence difference for the NOT operator between Base SAS and PROC SQL.
data chk;
do i=1 to 10;
a=1;
b=1;
c=0;
d=1;
output;
end;
do i=1 to 5;
a=1;
b=1;
c=.;
d=1;
output;
end;
run;
/* Returns 5 observations as expected */
proc sql;
select *
from chk
where . < b le 1 and not . < c < d;
quit;
/* Returns 0 observations because of the operator
precedence with NOT operator between Base SAS and PROC SQL */
proc print data=chk;
where . < b le 1 and not . < c < d;
run;
Date Modified: | 2013-10-29 12:18:38 |
Date Created: | 2013-09-13 11:05:52 |