# Lecture11 - Quiz How can you generate the same result with...

This preview shows pages 1–12. Sign up to view the full content.

1 Quiz How can you generate the same result with a DO WHILE statement? data invest; do until(Capital>1000000); Year+1; Capital+5000; Capital+(Capital*.045); end; run; proc print data=invest noobs; format capital dollar14.2; run;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Quiz Correct Answer How could you generate the same result with a DO WHILE statement? Change the DO UNTIL statement to a DO WHILE statement and modify the condition. data invest; Year+1; Capital+5000; Capital+(Capital*.045); end; run; proc print data=invest noobs; format capital dollar14.2; run;
3 Iterative DO Loop with a Conditional Clause You can combine DO WHILE and DO UNTIL statements with the iterative DO statement. General form of the iterative DO loop with a conditional clause: This is one method of avoiding an infinite loop in DO WHILE or DO UNTIL statements. DO index-variable = start TO stop <BY increment > WHILE | UNTIL ( expression ) ; < additional SAS statements> END;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Using DO UNTIL with an Iterative DO Loop Determine the value of the account again. Stop the loop if 30 years is reached or more than \$250,000 is accumulated. Year Capital \$264,966.67 PROC PRINT Output data invest; Capital+5000; Capital+(Capital*.045); end; run; proc print data=invest noobs; format capital dollar14.2; run; In a DO UNTIL loop, the condition is checked before the index variable is incremented.
5 Using DO WHILE with an Iterative DO Loop Determine the value of the account again, but this time use a DO WHILE statement. Year Capital \$264,966.67 PROC PRINT Output data invest; Capital+5000; Capital+(Capital*.045); end; run; proc print data=invest noobs; format capital dollar14.2; run; In a DO WHILE loop, the condition is checked after the index variable is incremented.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Nested DO Loops Nested DO loops are loops within loops. When you nest DO loops, use different index variables for each loop be certain that each DO statement has a corresponding END statement.
7 Business Scenario Create one observation per year for five years, and show the earnings if you invest \$5,000 per year with 4.5 percent annual interest compounded quarterly. data invest(drop=Quarter); do Year=1 to 5; Capital+5000; do Quarter=1 to 4; Capital+(Capital*(.045/4)); end; output; end; run; proc print data=invest noobs; run; 5 x 4 x

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8 Output: Nested DO Loops PROC PRINT Output Year Capital 1 5228.83 2 10696.95 3 16415.32 4 22395.39 5 28649.15
9 Quiz How can you generate one observation for each quarterly amount? data invest(drop=Quarter); do Year=1 to 5; Capital+5000; do Quarter=1 to 4; Capital+(Capital*(.045/4)); end; output; end; run; proc print data=invest noobs; run;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
10 Quiz Correct Answer How can you generate one observation for each quarterly amount? Move the OUTPUT statement to the inner loop and do not drop Quarter . data invest; do Year=1 to 5; Capital+5000; do Quarter=1 to 4; Capital+(Capital*(.045/4)); end; end; run; proc print data=invest noobs; run; Year Capital Quarter 1 5056.25 1 1 5113.13 2 1 5170.66 3 1 5228.83 4 2 10343.90 1 2 10460.27 2 Partial PROC PRINT Output
11 Business Scenario Compare the final results of investing \$5,000 a year for five years in three different banks that compound interest quarterly. Assume that each bank has a fixed interest rate, stored in the orion.banks data set.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 154

Lecture11 - Quiz How can you generate the same result with...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online