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
Try it.
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;
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;
@ 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
Thanks for your time!
Try it.
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?
sorry Reeza, i misunderstood your post...
its absolutely correct...i thought you are saying REMOVE output statement 🙂
Thanks a lot!
Yes Sir...
Thanks!
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.
Sorry about that!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.