BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shivamarrora0
Obsidian | Level 7

I want to do using loops

 

Hi, i have below data

p=100000

interest=10%

 will be the total amount after 4 years 

i want below screen result

 

YearPrincipalinterestsum
11000000.1110000
2110000.112100
3121000.113310
4133100.114641
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@shivamarrora0 wrote:
Thanks for the explanation , if possible can you please tell the code

I already supplied the code.

I usually solve such problems a little differently, though:

data test;
base = 100000;
int = .10;
do i = 0 to 5;
  p = base * (1 + int) ** i;
  output;
end;
run;

With that formula, you can calculate the value for any year in one single step.

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

Please show the code you already have (as this "problem" is really simple), and where it does not meet your expectations.

If you get unexpected messages in the log, post the log of the whole step.

shivamarrora0
Obsidian | Level 7

i  just started learning SAS.

 

data test;

p=100000;

int=.10;

do i = 1 to 5;

p+p*int;

 

end;

run;

 

this code will over right the orginal data

shivamarrora0
Obsidian | Level 7
i  just started learning SAS.
 
data test;
p=100000;
int=.10;
do i = 1 to 5;
p+p*int;
 
end;
run;
 
this code will over right the original data
Kurt_Bremser
Super User

@shivamarrora0 wrote:

i  just started learning SAS.

 

data test;

p=100000;

int=.10;

do i = 1 to 5;

p+p*int;

 

end;

run;

 

this code will over right the orginal data


When you run a data step that does not have an explicit output statement, SAS will do one everytime it reaches the end of a data step iteration. See it as a hidden "output" right before the run statement.

If you do not have a statement that let's SAS iterate automatically (like a set that reads from a dataset), then SAS will only do one iteration, and that's it.

So in your case, SAS performs the loop, and then writes one observation with the final values.

To get a series of observations, add the explicit output statement:

data test;
p = 100000;
int = .10;
do i = 1 to 5;
  p + p * int;
  output;
end;
run;

 

shivamarrora0
Obsidian | Level 7
Thanks for the explanation , if possible can you please tell the code
Kurt_Bremser
Super User

@shivamarrora0 wrote:
Thanks for the explanation , if possible can you please tell the code

I already supplied the code.

I usually solve such problems a little differently, though:

data test;
base = 100000;
int = .10;
do i = 0 to 5;
  p = base * (1 + int) ** i;
  output;
end;
run;

With that formula, you can calculate the value for any year in one single step.

mehak
Calcite | Level 5

if i invest $5000 each year in account .  after 15 yrs annual rate=10% and compound annual interest rate=10%.

 

also if a fixed term deposite of 25 yrs . Clculate total amount end of term with initial amount 1,00,000. annual interst rate 7%

.find compounded annually and monthly .

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1162 views
  • 0 likes
  • 3 in conversation