25
SAS tutorial 10/25

1020 sas實習課

Embed Size (px)

Citation preview

Page 1: 1020 sas實習課

SAS tutorial 10/25

Page 2: 1020 sas實習課

Overview

• PROC SUMMARY• PROC SORT

• LABEL• GOTO

Page 3: 1020 sas實習課

SUMMARY & SORT

Page 4: 1020 sas實習課

PROC SUMMARY

• Provides data summarization tools that compute descriptive statistics for variables across all observations or within groups of observations.

• Similar to PROC MEANS

Page 5: 1020 sas實習課

Syntax

Page 6: 1020 sas實習課

Differences to MEANS

• Cannot do t-test• Cannot calculate confidence limits• Cannot estimate quantiles

Page 7: 1020 sas實習課

Example 1

Page 8: 1020 sas實習課

DATA creativity

Page 9: 1020 sas實習課

Result

Page 10: 1020 sas實習課

Use “BY” option

Page 11: 1020 sas實習課

“Not sorted in ascending sequence”

Page 12: 1020 sas實習課

PROC SORT

• Orders SAS data set observations by the values of one or more character or numeric variables

Page 13: 1020 sas實習課

Syntax

Page 14: 1020 sas實習課

Example 2

Page 15: 1020 sas實習課

Result

Page 16: 1020 sas實習課

Example 1

Page 17: 1020 sas實習課
Page 18: 1020 sas實習課

Result

Page 19: 1020 sas實習課

LABEL & GOTO

Page 20: 1020 sas實習課

GOTO

• Directs program execution immediately to the statement label that is specified and, if followed by a RETURN statement, returns execution to the beginning of the DATA step.

Page 21: 1020 sas實習課

(Statement) Label

• Specifies a statement label that identifies the GOTO destination. The destination must be within the same DATA step. You must specify the label argument.

Page 22: 1020 sas實習課

Example 3

Page 23: 1020 sas實習課

• DATA info;Input X @@;If 1<=X<=5 then go to OK;

X=3; count+1;OK:SUMX+X;Cards;

• DATA info;Input X @@;If X<1 or X>5 then do;

X=3; count+1;end;SUMX+X;Cards;

X1 X1’ SUMX

1 1 1

2 2 3

6 3 6

4 4 10

7 3 13

1 1 14

Page 24: 1020 sas實習課

Return

Page 25: 1020 sas實習課

• DATA info;Input X @@;If 1<=X<=5 then go to OK;

X=3; count+1;Return;OK:SUMX+X;Cards;

• DATA info;Input X Y;If X<1 or X>5 then do;

X=3; count+1;End;else SUMX+X;Cards;X1 X1’ SUMX

1 1 1

2 2 3

6 3 3

4 4 7

7 3 7

1 1 8