BMTRY 789 Lecture 6: Proc Sort, Random Number Generators, and Do Loops Readings – Chapters 5 & 6 Lab Problem - Brain Teaser Homework Due – HW 2 Homework.

Slides:



Advertisements
Similar presentations
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Advertisements

How SAS implements structured programming constructs
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Tonight’s JavaScript Topics 1 Conditional Statements: if and switch The Array Object Looping Statements: for, while and do-while.
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
I OWA S TATE U NIVERSITY Department of Animal Science Modifying and Combing SAS Data Sets (Chapter in the 6 Little SAS Book) Animal Science 500 Lecture.
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 6: Loop Control Structures.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
JavaScript, Third Edition
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Chapter 14: Generating Data with Do Loops OBJECTIVES Understand iterative DO loops. Construct a DO loop to perform repetitive calculations Use DO loops.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
For Loops 2 ENGR 1181 MATLAB 9. For Loops and Looped Programming in Real Life As first introduced last lecture, looping within programs has long been.
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Chapter 20 Creating Multiple Observations from a Single Record Objectives Create multiple observations from a single record containing repeating blocks.
BMTRY 789 Lecture 3: Categorical Data and Dates Readings – Chapter 3 & 4 Lab Problems 3.1, 3.2, 3.19, 4.1, 4.3, 4.5 Homework – HW 2 Book Problems Due 6/24!
Chapter 16 Processing Variables with Arrays Objectives Group variables into one- and two-dimensional arrays Perform an action on array elements Create.
Sampling Methods  Sampling refers to how observations are “selected” from a probability distribution when the simulation is run. 1.
BMTRY 789 Introduction to SAS Programming Lecturer: Annie N. Simpson, MSc.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
CSC Intro. to Computing Lecture 13: PALGO. Announcements Midterm is in one week  Time to start reviewing  We will do more review in class Tuesday.
Chapter 4 Loops Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
Chapter 8 Iteration Dept of Computer Engineering Khon Kaen University.
Visual Basic Programming
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Latin Squares (Kirk, chapter 8) BUSI 6480 Lecture 7.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Programming Perl in UNIX Course Number : CIT 370 Week 3 Prof. Daniel Chen.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 10.
Before we get started…. First, a few things… Weighted Grading System Programming Style Submitting your assignments… The char and string variable types.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Time Series Data Processes by Tai Yu April 15, 2013.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
Control flow Ruth Anderson UW CSE 160 Spring
COMP Loop Statements Yi Hong May 21, 2015.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
BMTRY 789 Lecture9: Proc Tabulate Readings – Chapter 11 & Selected SUGI Reading Lab Problems , 11.2 Homework Due Next Week– HW6.
Chapter 6: Modifying and Combining Data Sets  The SET statement is a powerful statement in the DATA step DATA newdatasetname; SET olddatasetname;.. run;
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 8, 13, & 24 By Tasha Chapman, Oregon Health Authority.
Introduction to programming in java Lecture 21 Arrays – Part 1.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Next Week… Quiz 2 next week: –All Python –Up to this Friday’s lecture: Expressions Console I/O Conditionals while Loops Assignment 2 (due Feb. 12) topics:
Loops BIS1523 – Lecture 10.
JavaScript: Control Statements.
Repetition and Loop Statements
Outline Altering flow of control Boolean expressions
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
3 Control Statements:.
Computer Science Core Concepts
Loops.
Print the following triangle, using nested loops
Repetition (While Loop) LAB 9
Presentation transcript:

BMTRY 789 Lecture 6: Proc Sort, Random Number Generators, and Do Loops Readings – Chapters 5 & 6 Lab Problem - Brain Teaser Homework Due – HW 2 Homework for next week - HW 3 (Libname/Cards Quiz) NO CLASS

Summer 2009BMTRY 789 Intro to SAS Programming2 Random Number Generators

Summer 2009BMTRY 789 Intro to SAS Programming3 Proc Sort Primarily used to sort the observation of your data by a certain variable or collection of variables. However, it can also be used to create a new data set, subset your data, rename, drop, or keep variables, and format or label variables. An additional very important feature is to select out duplicate records

Summer 2009BMTRY 789 Intro to SAS Programming4 Proc Sort Options Almost always a good idea to use the OUT= option when using proc sort to do anything except for a simple sort. Why? Because Proc Sort automatically writes over your data set! Go to SAS user group paper to take a look at features and examples… NODUPKEY

Summer 2009BMTRY 789 Intro to SAS Programming5 Do-Loops Do-loops are one of the main tools of SAS programming. They exist in several forms, always terminated by an END; statement

Summer 2009BMTRY 789 Intro to SAS Programming6 Do-Loops (cont.) DO; -groups blocks of statements together DO OVER arrayname; -process array elements DO VAR=start TO end ; - range of numeric values DO VAR= list-of-values; DO WHILE (expression); (expression evaluated before loop) DO UNTIL (expression); (expression evaluated after loop) – guaranteed to be executed at least once *Some of these forms can be combined.

Summer 2009BMTRY 789 Intro to SAS Programming7 Iterative Do-loop Do loops can be nested. The following example calculates how long it would take for an investment with interest compounded monthly to double: Data interest; do rate = 4, 4.5, 5, 7, 9, 20; mrate = rate / 1200; *converts from percentage; months = 0; start = 1; Do While (start <2); start = start * (1 + mrate); months = months + 1; End; years = months / 12; output; End; Keep rate years; Run;

Summer 2009BMTRY 789 Intro to SAS Programming8 Random Number Functions SAS can generate random observations from discrete and continuous distributions. Binomial (n,p) -ranbin(seed,n,p) Exponential (~=1) - ranexp(seed) Standard Normal (µ=0; sigmaSquared=1) - rannor(seed) Poisson (mean > 0) - ranpoi(seed, mean) Uniform (interval (0,1) ) - ranuni(seed)

Summer 2009BMTRY 789 Intro to SAS Programming9 Seeds A SEED - is a number used by the random number generator to start the algorithm They can be any POSITIVE NUMBER or Zero 0 seed = a different series of numbers each time you run the program. Any positive seed = a repeatable series of numbers each time you run the program.

Summer 2009BMTRY 789 Intro to SAS Programming10 Practical Ex: Randomly Assign Subject to Study Groups Data Assign; Do Subj = 1 to 20; If RANUNI(123) LE.5 Then Group = 1; Else Group = 2; Output; End; Run; Proc Print Data = Assign; Run;

Summer 2009BMTRY 789 Intro to SAS Programming11 Practical Ex: Randomly Assign Subject to Study Groups (of equal size) Data Random; Do Subj = 1 to 20; Group = RANUNI(0) ; Output; End; Run; Proc Rank Data = Random Groups=2 Out=Split; Var Group; Run; Proc Print Data = Split Noobs; Run;

Summer 2009BMTRY 789 Intro to SAS Programming12 Here is your brain teaser, in- class assignment…

Summer 2009BMTRY 789 Intro to SAS Programming13 Practical Do-Loop Example You have a SAS data set DIET which contains variables ID, DATE, and WEIGHT. There are multiple records per ID, and the records are sorted by DATE within ID. The task is to create a new SAS data set DIET2 from DIET which contains only one record per subject, with each record containing the subject ID and the mean weight. (Could use Proc Means here but for the purpose of this exercise, we want to perform this task within the Data Step). Hints: Include a By ID statement after a SET statement in the DATA step, and then use First. and Last. variables.

Summer 2009BMTRY 789 Intro to SAS Programming14 Example Data Data Set DIET IDDATEWEIGHT 110/01/ /08/ /15/ /02/ /09/ /16/ /23/92202