{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# notes12 - 1 1 Notes 12 Iterative Data Processing DO Loops...

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

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.

Unformatted text preview: 1 1 Notes 12: Iterative Data Processing: DO Loops and Arrays 2 DO Loop Processing Statements within a DO loop execute for a specific number of iterations or until a specific condition stops the loop. DATA statement SAS statements DO statement iterated SAS statements END statement SAS statements RUN statement 3 DO Loop Processing You can use DO loops to –perform repetitive calculations –generate data –eliminate redundant code –execute SAS code conditionally. 4 Repetitive Coding • Compare the interest for yearly versus quarterly compounding on a \$50,000 investment made for one year at 7.5 percent interest. • How much money will a person accrue in each situation? 5 Repetitive Coding data compound; Amount=50000; Rate=.075; Yearly=Amount*Rate; Quarterly+((Quarterly+Amount)*Rate/4); Quarterly+((Quarterly+Amount)*Rate/4); Quarterly+((Quarterly+Amount)*Rate/4); Quarterly+((Quarterly+Amount)*Rate/4); run; 6 Repetitive Coding proc print data=compound noobs; run; Amount Rate Yearly Quarterly 50000 0.075 3750 3856.79 PROC PRINT Output 2 7 DO Loop Processing data compound(drop=Qtr); Amount=50000; Rate=.075; Yearly=Amount*Rate; do Qtr=1 to 4; Quarterly+((Quarterly+Amount)*Rate/4); end; run; 8 • The iterative DO statement executes statements between DO and END statements repetitively, based on the value of an index variable. • specification-1 … specification-n can represent a range of values or a list of specific values. The Iterative DO Statement DO index-variable = specification-1 <,… specification-n >; < additional SAS statements > END; DO index-variable = specification-1 <,… specification-n >; < additional SAS statements > END; 9 • The values of start , stop , and increment – must be numbers or expressions that yield numbers – are established before executing the loop. • Any changes to the values of stop or increment made within the DO loop do not affect the number of iterations. The Iterative DO Statement DO index-variable = start TO stop <BY increment >; DO index-variable = start TO stop <BY increment >; 10 The Iterative DO Statement What are the values of each of the four index variables? do i=1 to 12; do j=2 to 10 by 2; do k=14 to 2 by –2; do m=3.6 to 3.8 by .05; 1 2 3 4 5 6 7 8 9 10 11 12 13 2 4 6 8 10 12 14 12 10 8 6 4 2 3.60 3.65 3.70 3.75 3.80 3.85 Out of range Out of range Out of range Out of range 11 The Iterative DO Statement • item-1 through item-n can be either all numeric or all character constants, or they can be variables. • The DO loop is executed once for each value in the list. DO index-variable = item-1 < , …item-n> ; DO index-variable = item-1 < , …item-n> ; 12 do Month='JAN','FEB','MAR'; do Fib=1,2,3,5,8,13,21; do i=Var1,Var2,Var3; do j=BeginDate to Today() by 7; do k=Test1-Test50; The Iterative DO Statement How many times will each DO loop execute?...
View Full Document

{[ snackBarMessage ]}

### Page1 / 20

notes12 - 1 1 Notes 12 Iterative Data Processing DO Loops...

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

View Full Document
Ask a homework question - tutors are online