CHAPTER 7 (SAS Session) 2023
CHAPTER 7 (SAS Session) 2023
Haramaya University
Department of Statistics
Set by Kindu Kebede
JUNE, 2023
Advanced Statistics Using SAS
Overview of SAS
What is SAS?
• Began as a statistical package
• Also allows users to:
– Store data
– Manipulate data
– Create reports
• PDF
• Excel
• HTML
• XML
• RTF / Word
• Etc. Etc. Etc.
What is SAS?
• Also allows users to:
– Create graphs
– Create maps
– Send e-mails
– Create web applications
– Create iPhone Apps
– Access R
– Schedule regularly run reports
– Etc. Etc. Etc.
Overview …
7
Opening SAS
Log:
Details about jobs you’ve run,
including error messages
Explorer Window:
See libraries and
SAS datasets
Enhanced Editor:
Where you write your SAS code
Enhanced Editor Window
11
Cont….
12
THE LOG Window
13
THE LOG Window
14
The Output Window
Results tab:
List of previously
run results Output Window:
Basic view of results and output
(Also known as “Listing
Destination”)
Explorer Window
Explorer
Window
Results Window
Cont…
Cont…
Data Value, Variable, Observation, and Data Set
Rules for Naming Variables in SAS
24
Rules for SAS Statements
Cont..
Getting Data into SAS
Cont…
DATA steps:
Read and write data, manipulate data,
perform calculations, etc.
PROC steps:
Produce reports, summarize data, sort data,
create formats, generate graphs, etc. etc. etc.
PROC step examples
PROC step examples
PROC freq
Creates a basic frequency
table with:
Frequency
Percent
Cumulative Frequency
Cumulative Percent
“DATA=newdemo”
references the newdemo
dataset
TABLE statement indicates
which variable(s) to include
Can use multiple variables
and even create cross-tab tables
PROC step examples
PROC means
Creates a basic summary
table with:
N
Mean
Std Dev
Minimum
Maximum
Can specify which statistics
to use in table
“DATA=newdemo”
references the newdemo
dataset
VAR statement indicates
which variable(s) to include
Other notes
Step boundaries:
Each step is executed when a step
boundary is encountered
*comment statement;
or
/* comment statement */
Examining the Results
SAS Help
Where to learn more about SAS
Technical papers
SAS User Groups
Websites
Books
Classes
http://www.sascommunity.org/wiki/
Learning_SAS_-_Resources_You_Can’t_Live_Without
www.google.com
www.ats.ucla.edu/stat/sas
www.lexjansen.com
SAS Help and Documentation
Correcting SAS Errors
Data Management using SAS
Sorting Data
Questions?
Introduction on Variable Descriptive Data Analysis Inferential Data Analysis
Statistical Model
Response
categories:logit,probit,MLR,OLR
Data collection
Hypothesis Testing
Hypothesis:Is an assertion about a given population
parameter
* Paired T-TEST;
PROC TTEST DATA=data name;
paired pre*post;
RUN;
chickenData Cont...
Example:
data corn;
input yield fert field @@;
cards;
28 1 1 34 1 1 32 1 2 33 1 2 30 1 3 33 1 3
40 2 1 38 2 1 39 2 2 44 2 2 36 2 3 38 2 3
;
run;
proc mixed data=corn;
class fert field;
model yield=fert;
random field;
run;
*Note that you can also use the MIXED procedure to analyze mixed models. The
following statements use PROC MIXED to reproduce the mixed model analysis
of variance. the relevant part of the PROC MIXED results is shown in Output;
proc mixed data=machine method=type3;
class machine person;
model rating = machine;
random person machine*person;
run;
proc means;
by ins;
var response;
run;
Where; formula
proc reg data=data name;
model dep. var = ind.vars;
run;
data is the place of putting the file name of data used to
fit linear regression
Example: Consider ftstula.csv data set from your file and fit an
appropriate model for recovery status of the patients on Width of
ftstula(Wof),Length of ftstula(Lof),Bladder size(Bladsize),Place
of delivery(Pod).
# import ftstula.csv data sets
Example: Consider ed3.csv data set from your file and fit an
appropriate for CD4 count of patients on some covariates at
baseline
proc glimmix data=ed3;
CLASS FNS;
model CD4 = FNS AGE / s dist=Poisson;
run;
fit the poisson model for the data
Kindu.k