在SAS中按几个变量分组
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在SAS中按几个变量分组相关的知识,希望对你有一定的参考价值。
我想总结代理商,订单和日期的销售情况。但是,运行以下代码,我只收到总列的副本而不是总和。有什么建议?码:
(Select DISTINCT DATE, CUSTOMER, ORDERNR,
AREA, AGENT, Total, SUM(Total) AS TOTALSUM From data01 WHERE REPORT_DT between '2018-02-24' and '2018-02-25' GROUP BY DATE, CUSTOMER, ORDERNR,
AREA, AGENT, Total, ORDER BY AGENT)
答案
只是建议清理包含一些错误的代码 您不需要使用GROUP BY,并且在分组依据中的Total后面有一个错误的逗号
(Select
DATE
, CUSTOMER
, ORDERNR
, AREA
, AGENT
, Total
, SUM(Total) AS TOTALSUM
From data01
WHERE REPORT_DT between '2018-02-24' and '2018-02-25'
GROUP BY DATE
, CUSTOMER
, ORDERNR
, AREA
, AGENT
, Total
ORDER BY AGENT)
另一答案
从Total
删除GROUP BY
:
Select DATE, CUSTOMER, ORDERNR, AREA, AGENT, SUM(Total) AS TOTALSUM
From data01
where REPORT_DT between '2018-02-24' and '2018-02-25'
group by DATE, CUSTOMER, ORDERNR, AREA, AGENT;
以上是关于在SAS中按几个变量分组的主要内容,如果未能解决你的问题,请参考以下文章