SAS 中的累计余额

问题描述 投票:0回答:1

我在 SAS 中有这个数据集:

id 列_a 列_b
1 10 8
1 7 1
1 0 10
2 8 8
2 10 1
2 10 0

我需要计算每个 id、column_a (-)column_b 的累积余额。 想要的输出:

id 列_a 列_b 平衡
1 10 8 2
1 7 1 8
1 0 10 -2
2 8 8 0
2 10 1 9
2 10 0 19
loops math sas sas-macro accumulate
1个回答
0
投票

尝试

data want ;
  set have ;
  by id ;
  if first.id 
    then balance = (a-b) ;
    else balance + (a-b) ;
© www.soinside.com 2019 - 2024. All rights reserved.