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

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

View Full Document Right Arrow Icon
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;
Background image of page 1

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

View Full DocumentRight Arrow Icon
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;
Background image of page 2
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;
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
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.
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
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;
Background image of page 9

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
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.
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/12/2011 for the course ASB 1001,2522, taught by Professor Nicole during the One '09 term at University of New South Wales.

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 Right Arrow Icon
Ask a homework question - tutors are online