SAS-Do_Array

# SAS-Do_Array - SAS Do Loops Do And Arrays Last Updated : 29...

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

SAS SAS Do Loops Do Loops And And Arrays Arrays Last Updated : 29 June, 2004 Center of Excellence Data Warehousing

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

View Full Document
Objectives  Understand iterative DO loops  Use DO loops to generate data.  Use DO loops to eliminate redundant code.  Use DO loop processing to conditionally execute  code.
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;

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

View Full Document
DO Loop Processing You can use DO loops to perform repetitive calculations generate data eliminate redundant code execute SAS code conditionally.
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?

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

View Full Document
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;
Repetitive Coding proc print data=compound noobs; run; Amount Rate Yearly Quarterly 50000 0.075 3750 3856.79 What if you wanted to determine the quarterly compounded interest after a period of 20 years (80 quarters)? PROC PRINT Output

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

View Full Document
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;
The Iterative DO Statement 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. DO index-variable = specification-1 <,… specification-n >; < additional SAS statements > END;

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

View Full Document
The Iterative DO Statement The  values  of  start,  stop,  and  increment  are  established before executing the loop.   start,  stop,  and  increment  must  be  numbers  or  expressions that yield numbers. Any  changes  to  the  values  of  stop  or  increment  made within the DO loop do not affect the number  of iterations.  DO index-variable = start TO stop <BY increment >;
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 0 3.60 3.65 3.70 3.75 3.80 3.85 ... Out of range Out of range Out of range Out of range

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

View Full Document
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.
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/08/2010 for the course USE 3425 taught by Professor Raman during the Spring '10 term at Punjab Engineering College.

### Page1 / 121

SAS-Do_Array - SAS Do Loops Do And Arrays Last Updated : 29...

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

View Full Document
Ask a homework question - tutors are online