Partitioned Running Totals in SAS

后端 未结 4 492
忘掉有多难
忘掉有多难 2021-01-24 17:51

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 Val         


        
4条回答
  •  不要未来只要你来
    2021-01-24 18:25

    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;
    

提交回复
热议问题