Proc SQL 使用 SAS Grid 上的 SAS 9.4 和 PC 上的 SAS 9.3 给出不同的结果
Proc SQL giving different results using SAS 9.4 on SAS Grid and SAS 9.3 on PC
我们正在将我们的代码转换到 SAS Grid,我们在其中使用 Enterprise Guide 6.1 到 运行 SAS 9.4。一段代码给出的结果与我们在 PC 上 运行ning SAS 9.3 时得到的结果不同。我创建了一个示例数据集和代码,结果 returns 不同。 运行ning 在 Grid 上的结果(13 行有重复项)是在 select 语句中包含一列但不聚合它或在 group by 中使用它时的预期行为。 运行使用 SAS 9.3(6 个不同的行)对其进行处理的结果是我们想要的,但不是典型的 SAS 行为。我已经修改了代码(将 denom 添加到分组依据)以在网格上获得所需的结果,但想知道为什么代码 returns 在不同环境中 运行 时会产生不同的结果。有什么想法吗?
ETA:Grid使用了SAS 9.4,修改后的代码在group by中使用了denom。此外,我无法找到 Proc SQL 从 V 9.3 到 V 9.4 的更改文档。
proc sql;
create table work.test
(state char(2)
,county char(20)
,city char(20)
,id char(6));
quit;
proc sql;
insert into work.test (state, county, city, id)
values ('OH', 'Hamilton', 'Cincinnati', 'abc')
values ('OH', 'Hamilton', 'Cincinnati', 'def')
values ('OH', 'Hamilton', 'Cincinnati', 'ghi')
values ('OH', 'Hamilton', 'Mariemont', 'jkl')
values ('OH', 'Hamilton', 'Mariemont', 'mno')
values ('OH', 'Franklin', 'Columbus', 'pqr')
values ('OH', 'Franklin', 'Columbus', 'stu')
values ('TX', 'San Patricio', 'Ingleside', 'abc')
values ('TX', 'San Patricio', 'Taft', 'abc')
values ('TX', 'Nueces', 'Corpus Christi', 'abc')
values ('TX', 'Nueces', 'Corpus Christi', 'xyz')
values ('TX', 'Nueces', 'Corpus Christi', 'tuv')
values ('TX', 'Nueces', 'Corpus Christi', 'def');
quit;
proc sql;
create table freqs as
select a.state
, a.county
, a.city
, count(city) as numer
, denom
, round(count(city)/denom*100,.1) as percent
from work.test as a,
(select state, county, count(*) as denom from work.test group by state, county) as b
where a.state=b.state and a.county=b.county
group by a.state, a.county, a.city;
quit;
归根结底,您的查询写得不好。
如果您查看日志,您会看到这条注释:
NOTE: The query requires remerging summary statistics back with the
original data.
原因是 denom
不是汇总变量。这导致您的额外记录。这应该是您的查询的预期行为 - 13 行有重复项。
处理顺序是先连接表,再进行汇总计算。当 GROUP BY
语句不完整时,您会得到 NOTE:
将 b.denom
添加到分组依据,您将获得预期的 6 行。
至于为什么 SAS 给您不同的结果:我怀疑 GRID 上的 SAS 版本与您在 PC 上的不同。
编辑:
我认为这是详细说明问题的 SAS Note。他们在 9.3 的热修复中修复了它,并且本来是开箱即用的 9.4 的一部分:
http://support.sas.com/kb/46/832.html
我们正在将我们的代码转换到 SAS Grid,我们在其中使用 Enterprise Guide 6.1 到 运行 SAS 9.4。一段代码给出的结果与我们在 PC 上 运行ning SAS 9.3 时得到的结果不同。我创建了一个示例数据集和代码,结果 returns 不同。 运行ning 在 Grid 上的结果(13 行有重复项)是在 select 语句中包含一列但不聚合它或在 group by 中使用它时的预期行为。 运行使用 SAS 9.3(6 个不同的行)对其进行处理的结果是我们想要的,但不是典型的 SAS 行为。我已经修改了代码(将 denom 添加到分组依据)以在网格上获得所需的结果,但想知道为什么代码 returns 在不同环境中 运行 时会产生不同的结果。有什么想法吗?
ETA:Grid使用了SAS 9.4,修改后的代码在group by中使用了denom。此外,我无法找到 Proc SQL 从 V 9.3 到 V 9.4 的更改文档。
proc sql;
create table work.test
(state char(2)
,county char(20)
,city char(20)
,id char(6));
quit;
proc sql;
insert into work.test (state, county, city, id)
values ('OH', 'Hamilton', 'Cincinnati', 'abc')
values ('OH', 'Hamilton', 'Cincinnati', 'def')
values ('OH', 'Hamilton', 'Cincinnati', 'ghi')
values ('OH', 'Hamilton', 'Mariemont', 'jkl')
values ('OH', 'Hamilton', 'Mariemont', 'mno')
values ('OH', 'Franklin', 'Columbus', 'pqr')
values ('OH', 'Franklin', 'Columbus', 'stu')
values ('TX', 'San Patricio', 'Ingleside', 'abc')
values ('TX', 'San Patricio', 'Taft', 'abc')
values ('TX', 'Nueces', 'Corpus Christi', 'abc')
values ('TX', 'Nueces', 'Corpus Christi', 'xyz')
values ('TX', 'Nueces', 'Corpus Christi', 'tuv')
values ('TX', 'Nueces', 'Corpus Christi', 'def');
quit;
proc sql;
create table freqs as
select a.state
, a.county
, a.city
, count(city) as numer
, denom
, round(count(city)/denom*100,.1) as percent
from work.test as a,
(select state, county, count(*) as denom from work.test group by state, county) as b
where a.state=b.state and a.county=b.county
group by a.state, a.county, a.city;
quit;
归根结底,您的查询写得不好。
如果您查看日志,您会看到这条注释:
NOTE: The query requires remerging summary statistics back with the original data.
原因是 denom
不是汇总变量。这导致您的额外记录。这应该是您的查询的预期行为 - 13 行有重复项。
处理顺序是先连接表,再进行汇总计算。当 GROUP BY
语句不完整时,您会得到 NOTE:
将 b.denom
添加到分组依据,您将获得预期的 6 行。
至于为什么 SAS 给您不同的结果:我怀疑 GRID 上的 SAS 版本与您在 PC 上的不同。
编辑: 我认为这是详细说明问题的 SAS Note。他们在 9.3 的热修复中修复了它,并且本来是开箱即用的 9.4 的一部分: http://support.sas.com/kb/46/832.html