sas - 如何在 SAS 中按类型将观察结果分组在一起
问题描述
我有一个看起来像这样的 SAS 数据集
data test;
input id type $ quantity cost;
datalines;
1 one 2 3
2 one 3 4.5
3 two 1 5
4 three 3 12
5 two 4 20
6 three 7 28
7 one 4 6
8 two 3 15
;
run;
我的目标是根据类型汇总所有观察的数量和成本。最终结果应如下所示。
data test2;
input type $ combined_quantity combined_cost;
datalines;
one 9 13.5
two 8 40
three 10 40
;
run;
本质上,如果行如
id type quantity cost
4 three 3 12
6 three 7 28
存在,结果应该是
type combined_quantity combined_cost
three 10 40
作为基于相同类型的 2 行的总和
我该如何使用 SAS?任何帮助将不胜感激!
解决方案
proc means data=test nway;
class type;
var quantity cost;
output out=test2 (drop=_:) sum=combined_quantity combined_cost;
run;
推荐阅读
- java - 为什么我定义的类不能在 android studio 中正确读取并显示错误?
- reactjs - 重写和重定向配置以在 AWS amplify 上使用 react-strapi 部署反应应用程序?
- javascript - 使用 Javascript 操作对象并合并相似数据
- javascript - 使用ajax打印多数据
- javascript - 优化代码:有没有更好的方法将一个(较短的)数组映射到 Javascript 中的另一个(较长的)对象数组?
- python - 如何在列表中生成圆的坐标
- python-3.x - 使用 for 循环向 matplotlib 中的子图添加唯一标题
- swiftui - SwiftUI @Binding 误解
- google-chrome - 无法通过 burp 加载 https 站点
- laravel - 被 CORS 政策阻止并没有解决!Laravel + Vuejs