Problem Note 57896: PROC SQL might return incorrect results when a query against a view contains the sum of a CALCULATED column within a CASE expression
If an SQL procedure view is referenced in a FROM clause, incorrect results might occur when the sum of a CALCULATED column is used in a CASE expression. If a table is used in the FROM clause instead of a view, the correct results are returned.
Click the Full Code tab to see code that illustrates the difference in results when a table is queried instead of a view.
Click the Hot Fix tab in this note to access the hot fix for this issue.
Operating System and Release Information
SAS System | Base SAS | Microsoft Windows 8 Enterprise 32-bit | 9.3 TS1M2 | |
Microsoft Windows 8 Enterprise x64 | 9.3 TS1M2 | |
Microsoft® Windows® for x64 | 9.3 TS1M2 | |
z/OS 64-bit | 9.3 TS1M2 | |
z/OS | 9.3 TS1M2 | |
Microsoft Windows 8 Pro 32-bit | 9.3 TS1M2 | |
Microsoft Windows 8 Pro x64 | 9.3 TS1M2 | |
Microsoft Windows 8.1 Enterprise 32-bit | 9.3 TS1M2 | |
Microsoft Windows 8.1 Enterprise x64 | 9.3 TS1M2 | |
Microsoft Windows 8.1 Pro 32-bit | 9.3 TS1M2 | |
Microsoft Windows 8.1 Pro x64 | 9.3 TS1M2 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.3 TS1M2 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.3 TS1M2 | |
Microsoft Windows Server 2003 Standard Edition | 9.3 TS1M2 | |
Microsoft Windows Server 2003 for x64 | 9.3 TS1M2 | |
Microsoft Windows Server 2008 | 9.3 TS1M2 | |
Microsoft Windows Server 2008 R2 | 9.3 TS1M2 | |
Microsoft Windows Server 2008 for x64 | 9.3 TS1M2 | |
Microsoft Windows Server 2012 Datacenter | 9.3 TS1M2 | |
Microsoft Windows Server 2012 R2 Datacenter | 9.3 TS1M2 | |
Microsoft Windows Server 2012 R2 Std | 9.3 TS1M2 | |
Microsoft Windows Server 2012 Std | 9.3 TS1M2 | |
Microsoft Windows XP Professional | 9.3 TS1M2 | |
Windows 7 Enterprise 32 bit | 9.3 TS1M2 | |
Windows 7 Enterprise x64 | 9.3 TS1M2 | |
Windows 7 Home Premium 32 bit | 9.3 TS1M2 | |
Windows 7 Home Premium x64 | 9.3 TS1M2 | |
Windows 7 Professional 32 bit | 9.3 TS1M2 | |
Windows 7 Professional x64 | 9.3 TS1M2 | |
Windows 7 Ultimate 32 bit | 9.3 TS1M2 | |
Windows 7 Ultimate x64 | 9.3 TS1M2 | |
Windows Vista | 9.3 TS1M2 | |
Windows Vista for x64 | 9.3 TS1M2 | |
64-bit Enabled AIX | 9.3 TS1M2 | |
64-bit Enabled HP-UX | 9.3 TS1M2 | |
64-bit Enabled Solaris | 9.3 TS1M2 | |
HP-UX IPF | 9.3 TS1M2 | |
Linux | 9.3 TS1M2 | |
Linux for x64 | 9.3 TS1M2 | |
Solaris for x64 | 9.3 TS1M2 | |
*
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 code below illustrates the difference in results when a table is queried instead of a view.
data alfa;
a =1; b =1; c =1;
testvar=100;
run;
proc sql;
create view alfa2 as
select
(case when a not in (0,.) then 1 else 0 end) as ctr121_1 length = 8,
(case when a not in (0,.) then 1 else 0 end) as ctr121_2 length = 8,
(case when a not in (0,.) then 1 else 0 end) as ctr121_3 length = 8,
testvar
from alfa;
quit;
proc sql;
create table wrong as
select ctr121_1, ctr121_2, ctr121_3,
case when ctr121_1 =0 then 0 else 1 end as accumulo_ctr121_1 length = 8,
case when ctr121_2 =0 then 0 else sum(calculated accumulo_ctr121_1,1) end as accumulo_ctr121_2 length = 8,
case when ctr121_3 =0 then 0 else sum(calculated accumulo_ctr121_2,1) end as accumulo_ctr121_3 length = 8
from alfa2;
quit;
proc sql;
create table correct as
select ctr121_1, ctr121_2, ctr121_3,
case when ctr121_1 =0 then 0 else 1 end as accumulo_ctr121_1 length = 8,
case when ctr121_2 =0 then 0 else sum(testvar,1) end as accumulo_ctr121_2 length = 8,
case when ctr121_3 =0 then 0 else sum(testvar,1) end as accumulo_ctr121_3 length = 8
from alfa;
quit;
proc print data=wrong;
run;
proc print data=correct;
run;
Type: | Problem Note |
Priority: | high |
Date Modified: | 2016-04-28 13:54:44 |
Date Created: | 2016-03-18 12:52:22 |