Programming in SAS - PowerPoint PPT Presentation

About This Presentation
Title:

Programming in SAS

Description:

Each DATA step executes an implied loop from the first read statement (SET, ... the end of the instruction set (implied OUTPUT) unless there is an OUTPUT statement ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 15
Provided by: busin7
Learn more at: https://www.ou.edu
Category:

less

Transcript and Presenter's Notes

Title: Programming in SAS


1
Programming in SAS
  • How SAS implements structured programming
    constructs

2
SAS Philosophy
  • The Elephant philosophy
  • of programming
  • Remove everything that doesnt look like an
    elephant.
  • SAS manipulates tables one row at a time.

3
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

4
Sequence
Statement 1
Statement 2
Statement 3
Statement 4
Statement
5
Loops
Setup Statements
Setup Statements
DO WHILE
DO UNTIL
6
DO Statement
  • DO ...more SAS statements...
  • END
  • DO index-variablespecification-1 lt, . . .
    specification-ngt . . . more SAS statements . .
    .
  • END

7
DO WHILEUNTIL 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.

8
Examples
  • n0
  • do while(nlt5)
  • n n1
  • put n
  • end
  • n0
  • do until (nlt5)
  • n n1
  • put n
  • end

9
Examples
  • do i1 to 10
  • do count2 to 8 by 2
  • do i1 to 10 while (xlty)
  • do i2 to 20 by 2 until((x/3)gty)

10
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
11
IF-THEN/ELSE Statement
  • IF expression THEN statement ltELSE statementgt
  • Arguments
  • expression
  • is any SAS expression and is a required argument.
  • statement
  • can be any executable SAS statement or DO group.

12
SAS Selection Constructs
  • IF THEN ELSE
  • IF THEN
  • DO
  • Statements
  • END
  • ELSE
  • DO
  • Statements
  • END
  • Other else statements.

13
SELECT Statement
  • SELECT lt(select-expression)gt
  • WHEN-1 (when-expression-1 lt...,
    when-expression-ngt) statement
  • lt... WHEN-n (when-expression-1 lt...,
    when-expression-ngt) statementgt
  • ltOTHERWISE statement
  • END
  • (select-expression) specifies any SAS expression
    that evaluates to a single value.
  • (when-expression) specifies any SAS expression,
    including a compound expression.

14
SAS Selection Constructs (cont.)
  • SELECT (payclass)
  • WHEN ('monthly') amtsalary
  • WHEN ('hourly')
  • DO
  • amthrlywagemin(hrs,40)
  • IF hrsgt40 THEN PUT 'Check Timecard'
  • END / end of do /
  • OTHERWISE PUT 'Problem Observation'
  • END
Write a Comment
User Comments (0)
About PowerShow.com