Problem Note 67987: Reading data from an external data source (ODBC, Oracle, Teradata) using a PROC SQL query with a HAVING clause might produce an incorrect result
Reading data from an external data source (ODBC, Oracle, Teradata, and so on) using a PROC SQL query with a HAVING clause might produce an incorrect result.
This issue can happen in the following rare situations:
- The query contains identical column aliases in a SELECT and an in-line SELECT clause.
- The query contains a HAVING clause with this column alias.
A result set is created. However, if you have the SAS trace option enabled, the SAS log shows a message similar to the following:
ERROR: ORACLE prepare error: ORA-00904: "TABLE"."COL2": invalid identifier, while preparing the SQL for the database.
This message is an example of the error message that you receive when running against an Oracle database.
Here is example code that triggers this issue (Notice column alias COL2):
LIBNAME DB <DB ENGINE> <CONNECTION OPTIONS>;
PROC SQL;
CREATE TABLE WORK.TEST AS
SELECT
t1.COL1,
(SUM(t1.COL2)) AS COL2
FROM (
SELECT
t1.COL1,
(SUM(t1.COL2)) AS COL2
FROM DB.TABLE1 t1
INNER JOIN DB.TABLE2 t2 ON (t1.COL1 = t2.COL1)
GROUP BY t1.COL1
) t1
HAVING (CALCULATED COL2) > 0;
QUIT;
To work around the problem, use distinct aliases for the column name, as shown here:
LIBNAME DB <DB ENGINE> <CONNECTION OPTIONS>;
PROC SQL;
CREATE TABLE WORK.TEST AS
SELECT
t1.COL1,
(SUM(t1.COL2)) AS COL2_X
FROM (
SELECT
t1.COL1,
(SUM(t1.COL2)) AS COL2
FROM DB.TABLE1 t1
INNER JOIN DB.TABLE2 t2 ON (t1.COL1 = t2.COL1)
GROUP BY t1.COL1
) t1
HAVING (CALCULATED COL2_X) > 0;
QUIT;
A hot fix is planned for this issue.
Operating System and Release Information
SAS System | Base SAS | Microsoft Windows Server 2019 | 9.4 TS1M6 | 9.4 TS1M8 |
Windows 7 Enterprise 32 bit | 9.4 TS1M6 | 9.4 TS1M8 |
Windows 7 Enterprise x64 | 9.4 TS1M6 | 9.4 TS1M8 |
Windows 7 Home Premium 32 bit | 9.4 TS1M6 | 9.4 TS1M8 |
Windows 7 Home Premium x64 | 9.4 TS1M6 | 9.4 TS1M8 |
Windows 7 Professional 32 bit | 9.4 TS1M6 | 9.4 TS1M8 |
Windows 7 Professional x64 | 9.4 TS1M6 | 9.4 TS1M8 |
Windows 7 Ultimate 32 bit | 9.4 TS1M6 | 9.4 TS1M8 |
Windows 7 Ultimate x64 | 9.4 TS1M6 | 9.4 TS1M8 |
64-bit Enabled AIX | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows Server 2016 | 9.4 TS1M6 | 9.4 TS1M8 |
64-bit Enabled Solaris | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows Server 2012 Std | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows Server 2012 R2 Std | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows Server 2012 R2 Datacenter | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows Server 2012 Datacenter | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows 10 | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows 8.1 Pro x64 | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows 8.1 Pro 32-bit | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows 8.1 Enterprise x64 | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows 8.1 Enterprise 32-bit | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows 8 Pro x64 | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows 8 Pro 32-bit | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows 8 Enterprise x64 | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft Windows 8 Enterprise 32-bit | 9.4 TS1M6 | 9.4 TS1M8 |
Microsoft® Windows® for x64 | 9.4 TS1M6 | 9.4 TS1M8 |
z/OS | 9.4 TS1M6 | 9.4 TS1M8 |
z/OS 64-bit | 9.4 TS1M6 | 9.4 TS1M8 |
HP-UX IPF | 9.4 TS1M6 | 9.4 TS1M8 |
Linux for x64 | 9.4 TS1M6 | 9.4 TS1M8 |
Solaris for x64 | 9.4 TS1M6 | 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.
Type: | Problem Note |
Priority: | medium |
Date Modified: | 2021-06-03 07:40:56 |
Date Created: | 2021-06-02 10:01:54 |