SQL Group By在SAS中 - 替代?

时间:2014-02-13 14:44:51

标签: sas proc-sql

rsubmit;
proc sql;
create table wpffasdekpr2 as
select polnum, ordnnr, brkd, fsnr, fvpkd, mnr, mlopnr,coverfrom, coverto, nationalkey, exposuretype, COActivityCode, sum(COSumInsured) as SumIns, sum(AnnualBaseAmt) as SumAmt from wpffasdekpr
group by 
polnum, ordnnr, brkd, fsnr, fvpkd, mnr, mlopnr,coverfrom, coverto, nationalkey, exposuretype, COActivityCode;
quit;
endrsubmit;

此操作表如下所示:

enter image description here

我希望通过这个语句将前4行压缩成一行,并将两个最右边的变量求和。但是,该声明无效。输出表看起来像输入表。两个问题: 这是为什么?在通常的SQL我很肯定它会工作。 2.我怎样才能达到预期的效果?

日志:

508  rsubmit;
NOTE: Remote submit to SESKUX01 commencing.
1391  proc sql;
1392  create table wpffasdekpr2 as
1393  select polnum, ordnnr, brkd, fsnr, fvpkd, mnr, mlopnr,coverfrom, coverto, nationalkey, exposuretype, COActivityCode, sum(COSumInsured) as COsumInsured2, sum(AnnualBaseAmt) as AnnualBaseAmt2
1393! from wpffasdekpr
1394  group by
1395  polnum, ordnnr, brkd, fsnr, fvpkd, mnr, mlopnr,coverfrom, coverto, nationalkey, exposuretype, COActivityCode;
NOTE: Compressing data set WORK.WPFFASDEKPR2 increased size by 5.17 percent.
      Compressed is 29614 pages; un-compressed would require 28159 pages.
NOTE: Table WORK.WPFFASDEKPR2 created, with 28778049 rows and 14 columns.

1396  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           1:54.66
      cpu time            1:41.68


NOTE: Remote submit to SESKUX01 complete.

1 个答案:

答案 0 :(得分:2)

CoverFrom和CoverTo的时间或日期值是多少?如果时间,他们可能不一样。可能值得检查是否有任何格式应用于源数据集中的其他变量,因为按操作分组将处理基础值(而不是格式化/显示的结果)。

如果不这样做,我建议您一次使用一个组重新执行查询。此外,使用以下语法(编号分组)可以避免意外错误:

 proc sql;
 create table wpffasdekpr2 as
    select polnum, ordnnr, brkd, fsnr, fvpkd, mnr, mlopnr,coverfrom, coverto
       ,nationalkey, exposuretype, COActivityCode
       ,sum(COSumInsured) as SumIns, sum(AnnualBaseAmt) as SumAmt 
    from wpffasdekpr
    group by 1,2,3,4,5,6,7,8,9,10,11,12;