SAS中文论坛

标题: 请教关于累加的问题 [打印本页]

作者: shiyiming    时间: 2013-4-2 22:24
标题: 请教关于累加的问题
Name     Days   Money
Li           330   $11,000
Wang      112   $1,400
Li            124   $12,000
Chen        100   $3,000
Chen        93    $2,400
Li            224   $14,000
Wang        36     $900
有这样一个data ,要求按照不同的名字得到两组新的变量,累计的天数和钱数,新的两列变量应该这样表示
Cumulative_Days         Cumulative_Money
330                             $11,000
112                             $1,400
454                             $23,000
100                             $3,000
193                             $5,400
678                             $37,000
148                             $2,300
如果不按照名字从上到下依次累加的比较简单,但是如何按照不同的名字来累加天数和钱数呢?
有人知道吗,请指教
作者: shiyiming    时间: 2013-4-5 04:37
标题: Re: 请教关于累加的问题
1. get your data sorted by name
2. use RETAIN two variables for holding the accumulative total of days and money.
3. initialize these two variables (e.g. if first.name=1)
4. output the last record when the the last record reached (e.g if last.name=1) for every name.




欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/) Powered by Discuz! X3.2