SAS中的分区运行总计 [英] Partitioned Running Totals in SAS

查看:56
本文介绍了SAS中的分区运行总计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为现有数据集创建新列,该数据集是现有列的运行总数-由某些标识符分区?

How can I create a new column for an existing dataset that is the running total of an existing column - partitioned by some identifier?

ID |  Value |     New Value
---|--------|--------------------
1  |   10   |     10
1  |   5    |     15  = 10 + 5
1  |   3    |     18  = 10 + 5 + 3
2  |   45   |     45
2  |   15   |     60  = 45 + 15

我曾经在SQL(Oracle)中使用简单的SUM()OVER()语句来完成此操作,但显然PROC SQL不支持该语法.

I'm used to accomplishing this in SQL (Oracle) with a simple SUM() OVER() statement, but that syntax is apparently not supported in PROC SQL.

如果可能的话,我想在PROC SQL中完成此工作(与SAS编码相比,我对SQL有更多的经验).

If possible, I would like to accomplish this within PROC SQL (I am much more experienced with SQL than SAS coding).

谢谢!

迈克.

推荐答案

Joe-无论出于何种原因,您的答案均无效,但可以让我正确地找到答案.谢谢!

Joe - your answer did not work for whatever reason, but got me on the right track to figure it out. Thank you!

data want;
    set have;
    by id;
    if first.id then running_total = 0;
    if first.id then retained_total = 0;
    running_total = retained_total + value;
    retained_total = running_total;
    retain retained_total;
run;

这篇关于SAS中的分区运行总计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆