programming in sas n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Programming in SAS PowerPoint Presentation
Download Presentation
Programming in SAS

Loading in 2 Seconds...

play fullscreen
1 / 14

Programming in SAS - PowerPoint PPT Presentation


  • 78 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Programming in SAS' - whitley


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
programming in sas

Programming in SAS

How SAS implements structured programming constructs

sas philosophy
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
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
Sequence

Statement 1

Statement 2

Statement 3

Statement 4

Statement …

loops

Statement 1

Statement 1

Statement 2

Statement 2

Statement 3

Statement 3

***

***

Statement n

Statement n

Loops

Setup Statements

Setup Statements

DO WHILE

DO UNTIL

do statement
DO Statement

DO; ...more SAS statements...

END;

DOindex-variable=specification-1 <, . . . specification-n>; . . . more SAS statements . . .

END;

do while until statement
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
Examples

n=0;

do while(n<5);

n= n+1;

put n;

end;

n=0;

do until (n<5);

n= n+1;

put n;

end;

examples1
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
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-THEN/ELSE Statement
  • IFexpressionTHENstatement; <ELSEstatement;>
  • Arguments
  • expression
    • is any SAS expression and is a required argument.
  • statement
    • can be any executable SAS statement or DO group.
sas selection constructs
SAS Selection Constructs
  • IF … THEN …; ELSE …;
  • IF … THEN
      • DO;
        • Statements
      • END
    • ELSE
      • DO;
        • Statements
      • END;
    • Other else statements.
select statement
SELECT Statement

SELECT <(select-expression)>;

WHEN-1 (when-expression-1 <..., when-expression-n>) statement;

<... WHEN-n (when-expression-1 <..., when-expression-n>) statement;>

<OTHERWISEstatement;

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
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;