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

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

View Full Document Right Arrow Icon
SAS SAS Do Loops Do Loops And And Arrays Arrays Last Updated : 29 June, 2004 Center of Excellence Data Warehousing
Background image of page 1

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

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

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

View Full DocumentRight Arrow Icon
DO Loop Processing You can use DO loops to perform repetitive calculations generate data eliminate redundant code execute SAS code conditionally.
Background image of page 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?
Background image of page 5

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

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

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

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

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

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

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

View Full DocumentRight Arrow Icon
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.
Background image of page 12
Image of page 13
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 Right Arrow Icon
Ask a homework question - tutors are online