Need cumulative sum but not for the entire series

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

gandalf
Posts: 11
Joined: Mon Apr 16, 2012 12:25 pm

Need cumulative sum but not for the entire series

Postby gandalf » Wed May 16, 2012 10:27 pm

Hello,

I need to create the cumulative sum for a time variable for each person.

The first column has the personid. The second column has the information about time spent (time_spent) at each point.

Now, i want another column which gives me the cumulative time spent (CUMUL_TIME) by the person. Thus, the CUMUL_TIME variable always starts with zero and goes until the maximum value for each person. Can anyone please suggest me a way to do this?
Penguin_Knight
Posts: 473
Joined: Thu Apr 05, 2012 5:58 pm

Re: Need cumulative sum but not for the entire series

Postby Penguin_Knight » Thu May 17, 2012 6:02 am

Assume your data are properly sorted.

Code: Select all

IF personid NE lag(personid) | $casenum = 1 cumul_time = time_spent .
IF sysmis(cumul_time) and personid = lag(personid) cumul_time = time_spent + lag(cumul_time) .
EXECUTE .

Who is online

Users browsing this forum: No registered users and 1 guest

cron