Nesting DO Loops

Iterative DO statements can be executed within a DO loop. Putting a DO loop within a DO loop is called nesting.
do i=1 to 20; 
   SAS statements 
   do j=1 to 10; 
      SAS statements 
   end;
   SAS statements 
end;
The DATA step below computes the value of a one-year investment that earns 7.5% annual interest, compounded monthly.
data work.earn; 
   Capital=2000; 
   do month=1 to 12; 
      Interest=capital*(.075/12); 
      capital+interest; 
   end; 
run;
Let's assume the same amount of capital is to be added to the investment each year for 20 years. The new program must perform the calculation for each month during each of the 20 years. To do this, you can include the monthly calculations within another DO loop that executes 20 times.
 data work.earn; do year=1 ...

Get SAS Certification Prep Guide: Base Programming for SAS 9, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.