Contributor
Posts: 22

# Need Help in summarising data by commulating total

I have a dataset:

id_acc info_date  ov_credit ov_debit account_balance interest_rate_anuual

111     30june2007 500      700           6000                 0.18%

111     31jul2007   500      600             6008                  0.18%

111     31aug2007 500      200           8000                 0.18%

111     30sep2007 300      100           7000                 0.18%

111     31oct2007 400      300           9000                 0.18%

111     30nov2007 200      400           10000                 0.18%

I want the ouput in the following manner.Please suggest ome logic

account_bal1=account_balance+sum(ov_debit ,-ov_credit )+interest_rate_anuual;

account_bal2=account_bal1+sum(ov_debit ,-ov_credit )+interest_rate_anuual;

account_bal3=account_bal2+sum(ov_debit ,-ov_credit )+interest_rate_anuual;

Super User
Posts: 23,771

## Re: Need Help in summarising data by commulating total

Use RETAIN

I doubt yoor formula is quite correct though, but I'm also not 100% sure of what you're doing.

retain account_bal;

if _n_=1 then account_bal=account_balance;

account_bal=account_bal+sum(ov_debit,ov_credit )+interest_rate_anuual;

Valued Guide
Posts: 864

## Re: Need Help in summarising data by commulating total

data have;

infile cards dsd;

informat info_date date9.;

format info_date date9.;

input id_acc \$ info_date \$ ov_credit ov_debit account_balance interest_rate_anuual;

cards;

111,30jun2007,500,700,6000,0.18

111,31jul2007,500,600,6008,0.18

111,31aug2007,500,200,8000,0.18

111,30sep2007,300,100,7000,0.18

111,31oct2007,400,300,9000,0.18

111,30nov2007,200,400,10000,0.18

;

run;

data want;

set have;

account_bal1 = sum(account_balance,ov_debit,-ov_credit,interest_rate_anuual);

if not missing(account_bal1) then account_bal2 = sum(account_bal1,ov_debit,-ov_credit,interest_rate_anuual);

if not missing(account_bal2) then account_bal3 = sum(account_bal2,ov_debit,-ov_credit,interest_rate_anuual);

run;

Contributor
Posts: 30

## Re: Need Help in summarising data by commulating total

Hi  ,

Could you please eloborate the query a bit.

Discussion stats
• 3 replies
• 253 views
• 0 likes
• 4 in conversation