Professional Documents
Culture Documents
Part I
Department of Computing Services
Jie Chen Ph.D.
Jie.chen@umb.edu
March, 2003
3/13/2003 1
3/13/2003 2
3/13/2003 3
References
• SAS/STAT User’s Guide Volume 1,2 and 3
(version 8.0)
• SAS Language (version 6)
• SAS Language and Procedures (version 6)
• SAS Procedures Guide for Personal
Computers (version 6.03)
3/13/2003 4
Table of Contents
• Introduction
• To read and create data sets
• Submitting SAS programs
• Basic statistical procedures and graphs
– PROC PRINT
– PROC SORT
– PROC MEANS
– PROC FREQ
3/13/2003 5
1. Introduction
• SAS data management
• SAS procedures
• SAS program
• Open the SAS system
3/13/2003 6
SAS data Management
• The SAS system works with numerical and
character data.
• The data must be in a SAS data set or an
external file which can be read from SAS
program.
• Some external files can be imported to SAS
system
3/13/2003 7
SAS Procedures
• SAS procedures use data values from SAS
data sets to produce preprogrammed reports
requiring minimal effort from you
• An example:
PROC PRINT data = example;
title ‘This is a subset of data’;
run;
3/13/2003 8
A SAS Program
The statements in a SAS program are
divided into two kinds of steps:
• DATA steps:
– to create one or more new SAS data sets.
• PROC steps:
– To call a procedure from SAS library and to
execute that procedure.
3/13/2003 9
Open The SAS System
• Click Start/Programs
• Select The SAS System and
– The SAS System for Windows v 8
• The PROGRAM EDITOR-(Untitled )
window is active for syntax.
3/13/2003 10
3/13/2003 11
3/13/2003 13
3/13/2003 14
3/13/2003 16
3/13/2003 17
3/13/2003 18
Reading Data from a Text File
with Delimiters
data sample;
infile ‘a:\sample1.txt’;
input age educ $ race sex ptotinc famsize
fincome region;
run;
proc print data = sample;
run;
3/13/2003 19
3/13/2003 21
To Create a Text Data File
with fewer observations
data _null_;
set sample;
if age > 30;
file ‘a:\sub2.dat’;
put name $ age region;
run;
3/13/2003 22
PROC MEANS
data sample;
infile ‘a:\sample1.txt’;
input age educ $ race sex ptotinc famsize fincome
region;
run;
proc means data = sample;
var age ptotinc famsize ;
run;
3/13/2003 24
PROC SORT
proc sort data = sample out = list;
by sex region;
run;
proc print data = list;
run;
3/13/2003 25
PROC MEANS
with BY Statement
proc means data = list;
var ptotinc famsize famsize;
by sex;
run;
3/13/2003 26
PROC MEANS
with class Statement
proc means data = sample;
class sex;
var ptotinc famsize famsize;
run;
3/13/2003 27
PROC FREQ (one way)
proc freq data = sample;
table region race;
run;
3/13/2003 28
3/13/2003 29
3/13/2003 30
y = β 0
An Example of Linear
Regression
Y=a+bX+e
where x: is the regressor variable
(famsize).
a, b: are the unknown parameters.
y: is the response variable
(fincome).
e : is the unknown error.
3/13/2003 31
PROC REG
proc reg data = sample;
model fincome = famsize ;
output out = out1 p = pred1 r = resid1;
run;
3/13/2003 32
3/13/2003 33
A Fitted Equation
y = 11617 + 8165 x
3/13/2003 34
3/13/2003 35
Q-Q Plot
3/13/2003 36
PROC UNIVARIATE
proc univariate data = out1 normal plot;
var resid1;
run;
3/13/2003 37
3/13/2003 38