Академический Документы
Профессиональный Документы
Культура Документы
Outline
The SAS programming environment and language.
Introduction to the SAS Window Environment
the structure and components of SAS programs
SAS Data Sets
SAS libraries : temporary and permanent
Working with data sets in SAS
Selecting, Sorting
Printing
Using Basic Statistical Summary Procedures
Means Procedure
Freq Procedure
Plot Procedure
Univariate Procedure
SAS
(Statistical Analysis System)
The SAS programming environment and language used to read, process
and analyze data.
Introduction to the SAS Window Environment
The structure and components of SAS programs
SAS Data Sets
SAS libraries : Temporary and Permanent
Pull-down Menus
Log Window
Explorer
Window
Results
Editor Window
Output
Toolbar
Window Environment
Editor Window : is a text editor. Used to type in, edit, and submit /execute
SAS programs as well as edit other text files such as raw data files.
Log Window: lists program statements that are processed and gives notes,
warnings and errors.
Output Window : gives the output from the program if there is any
printable results.
Results Window : lists each part of your results in an outline form.
Explorer Window: The Explorer window gives you easy access to your SAS
files and libraries
SAS Programs
SAS programs are used to access, manage, analyze, and present the data
A SAS program written using the SAS language is a sequence of statements
executed in order.
SAS statements as with any language, there are a few rules to follow while
writing SAS programs.
File extension - .sas
A sample SAS program
DATA demo;
INPUT sale year;
DATALINES;
20 2001
34 2002
15 2003
21 2004
30 2005
;
PROC PRINT DATA= demo;
RUN;
SAS programs
Raw Data
Read in Data
Process Data
(Create new variables)
Data Step
Output Data
(Create SAS Dataset)
PROCs
SAS programs
2 Basic steps in SAS programs:
Data Steps
Read and Modify data
Create new data
Begins with DATA
statement
Proc Steps
perform specific analysis or
function
produce results or report
Data bankacct;
infile records;
input Name $ 1-10 AccountType $ 12-20
Deposit 22-25;
run;
proc print data=bankacct;
run;
proc means data=bankacct;
var deposit;
run;
SAS Programs
The end of the data or proc steps are indicated by:
RUN statement most steps
QUIT statement some steps
Beginning of another step (DATA or PROC statement)
Output generated from SAS program
SAS log
Information about the processing of the SAS program
Includes any warnings or error messages
Accumulated in the order the data and procedure steps are
submitted
SAS output
Reports generated by the SAS procedures
Accumulates output in the order it is generated
Depending on the library name that you use when you create a file, you
can store SAS files temporarily or permanently.
Temporary
Work library
SAS data files are deleted when session ends
Library reference name not necessary
Permanent
SASUSER library
SAS data sets are saved after session ends
You can create and access your own libraries
Eg : LIBNAME test 'H:\lab class ';
S. No.
1
2
3
4
5
6
7
Age
20
55
40
.
35
24
38
Gender
Income
F
M
F
M
M
M
F
10000
25000
35000
18000
12000
16000
30000
Job Status
L
M
H
M
L
M
H
4.
Manually Entering Raw Data Files in SAS program using the DATA Step
Few Examples
/*Reading raw data separated by spaces*/
data one;
input S_No Age Gender $ Income Job_Status $;
datalines;
1 20 F 10000 L
2 55 M 25000 M
3 40 F 35000 H
4 . M 18000 M
5 35 M 12000 L
6 24 M 16000 M
7 38 F 30000 H
;
proc print data = one;
title ' Problem 1';
Run;
*/
Using IF statement
Only writes observations to the new data set in which an expression is true;
General Form: IF <expression>;
Example: IF Job_status = H;
Print Procedure
Means Procedure
Freq Procedure
Chart Procedure
Plot Procedure
Univariate Procedure
Proc Print
Print Procedure
Proc Print
/* Printing selected variables
(use of var, where, sum, noobs, n, print selected observations, html output)*/
ods html file='try.html';
proc print data = test.one noobs n;
var S_No Age;
where age >30;
title ' Proc print usage';
sum income;
run;
ods html close;
proc print data = test.one(firstobs=2 obs=4) ;
var S_No Age income;
run;
Proc Means
Means Procedure
Proc Means is used to get the simple summary statistics of numeric variables
General Form:
PROC MEANS DATA=input_data_set options;
<SAS statements if any>;
RUN;
With no options or optional SAS statements, the Means procedure will print out the
number of non-missing values, mean, sd, min, and max for all numeric variables .
Example
proc means data=test.one;
class gender;
var income age;
run;
FREQ
Procedure
PROC FREQ is used to generate frequency tables (chracter variables)
Proc Freq
Proc Chart
Used to create frequency bar chart
General form: PROC CHART DATA=input_data;
VBAR variable_list /options;
RUN;
/*Use of Proc Chart to create frequency bar chart for characteristics variable*/
proc chart data=test.one;
vbar job_status ;
run;
/*Use of Proc Chart to create frequency bar chart for numeric variable*/
ods graphics on;
ods html ;
proc chart data=test.one;
vbar income /descrete; /* other options could be midpoints=values/ range or
levels=no.*/
run;
ods graphics off;
ods html close;
Proc Plot
Plot Procedure
Proc Plot
Example
* Create data for variables x and y;
data generate;
do x = 1 to 8;
y1 = x **2;
y2 = x**3;
output;
end;
proc print data = generate;
title 'generated data';
run;
/*A Simple Scatter Plot*/
proc plot data=generate;
plot y1*x;
run;
proc plot data=generate;
plot y1*x='1' y2*x='2'/overlay;
run;
Proc Univariate
Univariate Procedure
If the variable statement is not used, summary statistics will be produced for all
numeric variables in the input data set.
Options include:
PLOT produces Stem-and-leaf plot, Box plot, and Normal probability plot;
Example
proc univariate data = test.one;
var age;
run;