data one; do i=1 to 5; end; run; proc print data=one; run; * notice that it will only show the last iteration; * using the OUTPUT statement in the DO loop, it will show all iterations; data one; do i=1 to 5; output; end; run; proc print data=one; run; data two; do j=2 to 8 by 2; end; run; proc print data=two; run; data three; do k=10 to 2 by -2; end; run; proc print data=three; run; data doloop1 ; do count = 1 to 10 by 2 ; output ; end ; proc print ; title 'Data set doloop1' ; run ; data doloop2 ; do count = 10 to 1 by -2 ; output ; end ; proc print ; title 'Data set doloop2' ; run ; * To find yearly quarterly compouding for one year; * It's not too bad to write 1 yearly and 4 quarterly statements; data int1; Amount=50000; Rate=.045; Yearly=Amount*Rate; Quarterly+((Quarterly+Amount)*Rate/4); Quarterly+((Quarterly+Amount)*Rate/4); Quarterly+((Quarterly+Amount)*Rate/4); Quarterly+((Quarterly+Amount)*Rate/4); run; proc print data=int1; run; * For 20 years (80 quarters); data int; Amount=50000; Rate=.045; Yearly=Amount*Rate; Yearly=Amount*Rate; . . . and so on for 20 years (20 statements) Quarterly+((Quarterly+Amount)*Rate/4); Quarterly+((Quarterly+Amount)*Rate/4); . . . and so on for 80 quarters (80 statements) NO THANKS! * This one is better (fewer statements); data compound1(drop=i); Amount=50000; Rate=.045; do i=1 to 20; Yearly +(Yearly+Amount)*Rate; * above statement will add each previous calculation to the next one; end; do i=1 to 80; Quarterly+((Quarterly+Amount)*Rate/4); * above statement will add each previous calculation to the next one; end; run; proc print data=compound1 noobs; run; * Showing each year and quarterly growth rather than just total; data compound2(drop=i); Amount=50000; Rate=.045; do i=1 to 20; Yearly +(Yearly+Amount)*Rate; output; end; do i=1 to 80; Quarterly+((Quarterly+Amount)*Rate/4); output; end; run; proc print data=compound2 noobs; run; * DO UNITL; data dountil; do until(Capital>1000000); Year+1; Capital+5000; Capital+(Capital*.045); end; run; proc print data=dountil noobs; format Capital dollar14.2; run; * DO WHILE; data dowhile; do Year=1 to 30 while(Capital<=250000); Capital+5000; Capital+(Capital*.045); end; run; proc print data=dowhile noobs; format Capital dollar14.2; run; * Nested DO loop; data nested; do Year=1 to 5; Capital+5000; do Quarter=1 to 4; Capital+(Capital*(.045/4)); output; end; output; end; run; proc print data=nested noobs; format Capital dollar14.2; run; *alternative method not showing the quarter variable; data nested(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=nested noobs; var year quarter capital; format Capital dollar14.2; run;