## count interest

Solved
Regular Contributor
Posts: 225

# count interest

Hi Guys  - i need some help here please...

if i run below code, 1st obs for variable 'capital'  is 1010 and its adding interest in first obs of capital itself...i want first obs for capital same, 1000, and then interest for first obs,10, adds on second obs of capital (not in first obs itself...)...

Thanks!

data test;

capital=1000;

do month=1 to 12;

interest=capital*.12/12;

capital+interest;

output;

end;

run;

-----------------------------------------------

capital     month    interest

1010        1            10

1020.1     2            10.1

------------------------------------------------

but i want this,

capital     month    interest

1000        1            10

1010        2            10.1

Accepted Solutions
Solution
‎11-18-2013 05:12 PM
Super User
Posts: 23,763

## Re: count interest

All Replies
Super Contributor
Posts: 418

## Re: count interest

This is a very un-intelligent answer, but you can simply add an if then loop to your process logic. so it would look like this.

data test;

capital=1000;

do month=1 to 12;

if month~=1 then do;

interest=capital*.12/12;

capital+interest;

end;

output;

end;

run;

Likewise you could initalize your values and then start your loop at a later month (whichever is easier).

data test;

capital=1000;

interest=.;

month=1;

output;

do month=2 to 12;

interest=capital*.12/12;

capital+interest;

output;

end;

run;

Super User
Posts: 23,763

## Re: count interest

Move the output statement before the increment statement

data test;

capital=1000;

do month=1 to 12;

interest=capital*.12/12;

output;

capital+interest;

end;

run;

Regular Contributor
Posts: 225

## Re: count interest

@ Thanks Ano...--- but in both cases,

capital     month    interest

1000        1            .

1010        2            10

1020.1     3            10.1

but i think this is incorrect because for 2nd obs capital value is right, 1010 but interest would be 10.1 which is 10 in your both cases...this is very confusing for me at least...

@ Reeza _ i think it will show only 1 obs 13th with same result as if we use output with all 12 obs......i want to see below...if we can do this ,...

capital     month    interest

1000        1            10

1010        2            10.1

Solution
‎11-18-2013 05:12 PM
Super User
Posts: 23,763

Try it.

PROC Star
Posts: 8,164

## Re: count interest

What do you want the interest to be for the other 10 months?  Your initial code keeps the rate the same for each month.  Is that what you want?

Regular Contributor
Posts: 225

## Re: count interest

sorry Reeza, i misunderstood your post...

its absolutely correct...i thought you are saying REMOVE output statement :-)

Thanks a lot!

Regular Contributor
Posts: 225

## Re: count interest

Yes Sir...

Thanks!

Super Contributor
Posts: 418

## Re: count interest

Ah I'm sorry I glazed over your want and have too quickly!

I thought you wanted the interest to begin calculating in the second month and be applied at the same time, hence the solution.