Professional Documents
Culture Documents
2
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
3
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Objectives
List the components of a SAS program.
4
4
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
SAS Programs
A SAS program is a sequence of one or more steps.
5
5
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
6
6
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Step Boundaries
SAS steps begin with either of the following:
a DATA statement
a PROC statement
7
7
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
p102d01
8
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
p102d01
9
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
p102d01
10
10
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
p102d01
11
11
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
p102d01
12
12
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Idea Exchange
How does SAS detect the end of each step in this program?
data work.newsalesemps;
length First_Name $ 12
Last_Name $ 18 Job_Title $ 25;
infile "&path\newemps.csv" dlm=',';
input First_Name $ Last_Name $
Job_Title $ Salary;
run;
13
13
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
14
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Objectives
Describe various processing modes and SAS
interfaces.
Define the three primary tabs or windows used within
a SAS interface.
Submit a SAS program to create the course data files.
Submit the SAS program introduced in the previous
section.
15
15
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Processing Modes
The following are two possible processing modes for
submitting a SAS program:
16
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
SAS Interfaces
There are three possible SAS interfaces for processing a
SAS program in interactive mode.
SAS SAS
Windowing Enterprise SAS
Environment Guide Studio
17
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
SAS Interfaces
Past Present
SAS SAS
Windowing Enterprise SAS
Environment Guide Studio
18
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
19
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
20
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
SAS Studio
SAS Studio is a web client that is accessed through an
HTML5-compliant web browser.
21
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
22
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Results Viewer
Results Results Results
or Output
23
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
24
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
25
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Objectives
Identify the characteristics of SAS statements.
Define SAS syntax rules.
Document a program using comments.
Diagnose and correct a program with errors.
26
26
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Business Scenario
Well-formatted, clearly documented SAS programs are
an industry best practice.
27
27
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
data work.newsalesemps;
length First_Name $ 12
Last_Name $ 18 Job_Title $ 25;
infile "&path\newemps.csv" dlm=',';
input First_Name $ Last_Name $
Job_Title $ Salary;
run;
p102d01
28
28
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
29
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
30
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
p102d02
31
31
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
32
32
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Recommended Formatting
Begin each statement on a new line.
Use white space to separate words and steps.
Indent statements within a step.
Indent continued lines in multi-line statements.
data work.newsalesemps;
length First_Name $ 12
Last_Name $ 18 Job_Title $ 25;
infile "&path\newemps.csv" dlm=',';
input First_Name $ Last_Name $
Job_Title $ Salary; conventional
run; formatting
formatting
proc print data=work.newsalesemps;
run;
Program Documentation
You can embed comments in a program as explanatory
text.
/* create a temporary data set, newsalesemps */
/* from the text file newemps.csv */
34
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
SAS Comments
This program contains four comments.
*----------------------------------------*
| This program creates and uses the |
| data set called work.newsalesemps. |
*----------------------------------------*;
data work.newsalesemps;
length First_Name $ 12 Last_Name $ 18 1
Job_Title $ 25;
infile "&path\newemps.csv" dlm=',';
input First_Name $ Last_Name $
Job_Title $ Salary /* numeric */;
run;
/*
proc print data=work.newsalesemps;
run;
*/
proc means data=work.newsalesemps;
* var Salary ;
run;
p102d03
35
35
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
36
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
37
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Business Scenario
Orion Star programmers must be able to identify and
correct syntax errors in a SAS program.
38
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Syntax Errors
A syntax error is an error in the spelling or grammar of
a SAS statement. SAS finds syntax errors as it compiles
each SAS statement, before execution begins.
Examples of syntax errors:
misspelled keywords
unmatched quotation marks
missing semicolons
invalid options
39
39
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
daat work.newsalesemps;
length First_Name $ 12
Last_Name $ 18 Job_Title $ 25;
infile "&path\newemps.csv" dlm=',';
input First_Name $ Last_Name $
Job_Title $ Salary;
run;
p102d04
40
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
p102d04
41
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Syntax Errors
Syntax errors in a SAS program can possibly be detected
based on the color of the syntax on the Editor tab or in the
window.
42
42
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Syntax Errors
When SAS encounters a syntax error, it writes a warning
or error message to the log.
WARNING 14-169: Assuming the symbol DATA was misspelled as daat.
43
43
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
p102d05
44
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
46
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
49
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
50
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
51
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
52
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
53
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
54
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
55
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
56
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
57
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
58
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
59
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
60
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
61
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
62
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
65
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
66
Business Analytics
ST521 – Base SAS I