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

Info icon This 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
Image of page 1

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

View Full Document Right 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.
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;
Image of page 3

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

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

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

View Full Document Right 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;
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
Image of page 7

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

View Full Document Right 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;
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;
Image of page 9

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

View Full Document Right 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 >;
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
Image of page 11

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern