hi guys, I need your help here please i have this dataset (mylib.active_suscribers_grouped) below and i need to add two more fields to it (opening and closing balance ) grouped by calendar day.The closing balance =opening balance+Start+Restarted-Suspension-Termination and the opening balance is the closing balance from the previous day.The opening balance for 12/23/2012 is given to me. Calendar_Day Status Sum 12/23/2012 Terminated 1 12/24/2012 Restarted 2 12/24/2012 Start 3 12/24/2012 Suspension 4 12/24/2012 Terminated 5 12/25/2012 Restarted 6 12/25/2012 Terminated 7 so i need to get something like this: Calendar_Day Status Sum opening_balance closing_balance 12/23/2012 Terminated 1 5 4 12/24/2012 Restarted 2 4 0 12/24/2012 Start 3 4 0 12/24/2012 Suspension 4 4 0 12/24/2012 Terminated 5 4 0 12/25/2012 Restarted 6 0 -1 12/25/2012 Terminated 7 0 -1 and i am using this code below but i am not gettin what i am supposed to.Where i am wrong,please? data mylib.active_suscribers_summed; do _n_ = 1 by 1 until(last.calendar_day); set mylib.active_suscribers_grouped; by calendar_day; if _n_=1 then do; opening_balance=5; if status='Restarted' or status='Start' then Closing_balance=sum(opening_balance,Sum); else Closing_balance=sum(opening_balance,-Sum); end; if _n_ ne 1 then do; opening_balance=lag(closing_balance); if status='Restarted' or status='Start' then Closing_balance=sum(Opening_Balance,Sum); else Closing_balance=sum(Opening_balance,-Sum);end;end; do _n_ = 1 to _n_ ; set mylib.active_suscribers_grouped; output ; end ; run; the only thing i am getting right is the opening/closing balance for 12/23/2012 Thanks
... View more