How SAS implements structured programming constructs

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Iteration While / until/ for loop. Iteration: while/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initalise.
Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
While loops.
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Desk Checking. Desk checking is a manual (non computerised) technique for checking the logic of an algorithm. The person performing the desk check effectively.
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
Dependency Analysis We want to “parallelize” program to make it run faster. For that, we need dependence analysis to ensure correctness.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Chapter 61 Post Test Loop Do statement(s) Loop Until condition Loop is executed once and then the condition is tested. If it is False, the loop is run.
Program Design and Development
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
Loops are MATLAB constructs that permit us to execute a sequence of statements more than once. There are two basic forms of loop constructs: i. while.
Chapter 14: Generating Data with Do Loops OBJECTIVES Understand iterative DO loops. Construct a DO loop to perform repetitive calculations Use DO loops.
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
CPS120 Introduction to Computer Science Iteration (Looping)
Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Overview of Java Loops By: Reid Hunter. What Is A Loop? A loop is a series of commands that will continue to repeat over and over again until a condition.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CPS120 Introduction to Computer Science Iteration (Looping)
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Follow up from lab See Magic8Ball.java Issues that you ran into.
By Sasikumar Palanisamy
Sequence, Selection, Iteration The IF Statement
Think What will be the output?
Programming Fundamentals
Expressions and Control Flow in JavaScript
Loop Control Structure.
When I want to execute the subroutine I just give the command Write()
Topic 1: Problem Solving
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Chapter 8: More on the Repetition Structure
3.5- The while Statement The while statement has the following syntax:
Intro to Computer Science CS1510 Dr. Sarah Diesburg
What output is produced by the following fragment?
Computer Science Core Concepts
ICT Programming Lesson 3:
Flow of Control.
Seating “chart” Front - Screen rows Back DOOR.
PROGRAM FLOWCHART Iteration Statements.
Desk Checking.
CSC1401 Manipulating Pictures 2
REPETITION Why Repetition?
Presentation transcript:

How SAS implements structured programming constructs Programming in SAS How SAS implements structured programming constructs

SAS Philosophy The “Elephant philosophy of programming” Remove everything that doesn’t look like an elephant. SAS manipulates tables one row at a time.

DATA Steps Program statements are executed within data steps Code is executed in the order that it appears Instruction sets in SAS end with a DATA, PROC, or RUN statement Each DATA step executes an implied loop from the first read statement (SET, MERGE, INPUT, etc.) to the start of the next instruction set Data records are output at the end of the instruction set (implied OUTPUT) unless there is an OUTPUT statement

Sequence Statement 1 Statement 2 Statement 3 Statement 4 Statement …

Loops Setup Statements Setup Statements DO WHILE Statement 1 Statement n *** DO UNTIL Statement 1 Statement 2 Statement 3 Statement n ***

DO Statement DO; ...more SAS statements... END; DO index-variable=specification-1 <, . . . specification-n>; . . . more SAS statements . . .

DO WHILE|UNTIL Statement The UNTIL expression is evaluated at the bottom of the loop after the statements in the DO loop have been executed. If the expression is true, the DO loop does not iterate again. The WHILE expression is evaluated at the top of the loop before the statements in the DO loop are executed. If the expression is true, the DO loop iterates. If the expression is false the first time it is evaluated, the DO loop does not iterate even once.

Examples n=0; do while(n<5); n= n+1; put n; end; do until (n<5);

Examples do i=1 to 10; do count=2 to 8 by 2; do i=1 to 10 while (x<y); do i=2 to 20 by 2 until((x/3)>y);

Selection Select Case 1 Case 2 Case 3 Statement 1a Statement 1b Statement 1c Statement 2a Statement 2b Statement 2c Statement 3a Statement 3c Statement 3c Statement … Statement … Statement …

IF-THEN/ELSE Statement IF expression THEN statement; <ELSE statement;> Arguments expression is any SAS expression and is a required argument. statement can be any executable SAS statement or DO group.

SAS Selection Constructs IF … THEN …; ELSE …; IF … THEN DO; Statements END ELSE END; Other else statements.

SELECT Statement SELECT <(select-expression)>; WHEN-1 (when-expression-1 <..., when-expression-n>) statement; <... WHEN-n (when-expression-1 <..., when-expression-n>) statement;> <OTHERWISE statement; END; (select-expression) specifies any SAS expression that evaluates to a single value. (when-expression) specifies any SAS expression, including a compound expression.

SAS Selection Constructs (cont.) SELECT (payclass); WHEN ('monthly') amt=salary; WHEN ('hourly') DO; amt=hrlywage*min(hrs,40); IF hrs>40 THEN PUT 'Check Timecard'; END; /* end of do */ OTHERWISE PUT 'Problem Observation'; END;