Transcript Chapter 5

Chapter 5
Enhancing Output
Section 5.1
Customizing Report
Appearance
Objectives



3
Define titles and footnotes to enhance reports.
Define descriptive column headings.
Use SAS system options.
SAS Code
TITLEn
NUMBER|NONUMBER
FOOTNOTEn
PAGENO=
LABEL
FORMAT
SPLIT=
w.d
OPTIONS
$w.
DATA|NODATE
COMMAw.d
LINESIZE\LS
DOLLARw.d
PAGESIZE|PS
4
Enhancing Output
In this chapter, you will make the output appear more
polished.
You will add titles, change the column headings, and
display the Salary values with a $ in the output.
5
Defining Titles and Footnotes
You use titles and footnotes to enhance reports.
General form of the TITLE statement:
TITLEn 'text ';
General form of the FOOTNOTE statement:
FOOTNOTEn 'text ';
Example:
title 'Flight Crew Employee Listing';
footnote 'Employee Review';
6
Defining Titles and Footnotes





7
Titles
Titles remain active until
– changed
– cancelled
– you end your SAS session.
Titles appear at the top of page.
The default title is The SAS
System.
The value of n can be from 1
to10.
– Where n is title line number.
– An unnumbered TITLE is
equivalent to TITLE1.
The null TITLE statement,
title;, cancels all titles.





Footnotes
Footnotes remain active until
– changed
– cancelled
– you end your SAS session.
Footnotes appear at bottom of
page.
No default footnote
The value of n can be from 1
to10.
– Where n is the footnote line #
– An unnumbered FOOTNOTE
is equivalent to
FOOTNOTE1.
The null FOOTNOTE statement,
footnote;, cancels all
footnotes.
Changing Titles and Footnotes
Submit a TITLE statement.
title 'International Airlines';
Then submit a title on line 4.
title4 'United States Data';
What will appear in the output? Submit a step that
produces a report to see the titles.
8
Titles and Footnotes
title1 'International Airlines';
title4 'United States Data';
proc print data=ia.empdata;
run;
Partial Output
International Airlines
United States Data
9
Obs
Emp
ID
LastName
1
2
3
4
0031
0040
0071
0082
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
PILOT
FLTAT
FLTAT
PILOT
50221.62
23666.12
21957.71
96387.39
...
Titles and Footnotes
title1 'International Airlines';
title4 'United States Data';
proc print data=ia.empdata;
run;
Partial Output
International Airlines
United States Data
10
Obs
Emp
ID
LastName
1
2
3
4
0031
0040
0071
0082
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
PILOT
FLTAT
FLTAT
PILOT
50221.62
23666.12
21957.71
96387.39
...
Titles and Footnotes
title1 'International Airlines';
title4 'United States Data';
proc print data=ia.empdata;
run;
Titles 2 & 3
are blank.
Partial Output
International Airlines
United States Data
11
Obs
Emp
ID
LastName
1
2
3
4
0031
0040
0071
0082
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
PILOT
FLTAT
FLTAT
PILOT
50221.62
23666.12
21957.71
96387.39
Titles and Footnotes




Titles and footnotes are global statements.
They remain in effect until they are specifically
changed, cancelled, or you end your SAS session.
They can be placed above the PROC step or inside
the step.
The next step that produces output will also have the
title, unless you change it.
title1 'My Weekly Allowance';
title3 'The Pittance';
proc print data=ia.allowance;
run;
12
Titles and Footnotes
!

If you place the title or footnote after the step, it will
not appear on your report. Why?
SAS processes programs step by step, statement
by statement. The report is already produced
before SAS processes the title. SAS will not go
back to insert the title.
proc print data=ia.empdata;
run;
title 'This is the new title.';
Partial
Output
The SAS System
13
Obs
Emp
ID
LastName
1
2
3
4
0031
0040
0071
0082
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
PILOT
FLTAT
FLTAT
PILOT
50221.62
23666.12
21957.71
96387.39
Titles and Footnotes
If you submit a second PROC PRINT step, the new title
appears in the report.
Submitted
on previous
slide
proc print data=ia.empdata;
run;
title 'This is the new title.';
proc print data=ia.empdata;
run;
This is the new title.
14
Obs
Emp
ID
LastName
1
2
3
4
5
0031
0040
0071
0082
0091
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
50221.62
23666.12
21957.71
96387.39
32278.40
Titles and Footnotes
How do you change a title or footnote?
Simply submit another title or footnote
statement to replace it.
15
Changing Titles and Footnotes
TITLEn or FOOTNOTEn
 replaces a previous title or footnote with the same
number
 cancels all titles or footnotes with higher numbers.
What does that mean?
Set the title on lines 1 and 4 to clarify this.
16
Changing Titles and Footnotes
Previously, you submitted the following:
title1 'International Airlines';
title4 'United States Data';
You now need to change the title on line 4. It should read
as shown:
Best Employees EVER
To do this, you need to submit another TITLE4 statement
with the new title.
17
Titles and Footnotes
Example:
title4 'Best Employees EVER';
proc print data=ia.empdata;
run;
SAS will replace a
title with the same
number.
The first title4
is replaced with
the new text.
International Airlines
Best Employees EVER
18
Obs
Emp
ID
LastName
1
2
3
4
0031
0040
0071
0082
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
PILOT
FLTAT
FLTAT
PILOT
50221.62
23666.12
21957.71
96387.39
Changing Titles and Footnotes
Your company was purchased. You need to change the
title on the first line to read:
Milky Way Airlines
Submit this code:
title 'Milky Way Airlines';
Remember, title is the same as title1.
Remember
19
Titles and Footnotes
title 'Milky Way Airlines';
proc print data=ia.empdata; What happened to
run;
the title on line 4?
Milky Way Airlines
20
Obs
Emp
ID
LastName
1
2
3
4
0031
0040
0071
0082
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
PILOT
FLTAT
FLTAT
PILOT
50221.62
23666.12
21957.71
96387.39
Changing Titles and Footnotes
What did happen to the title on line 4?
21

A TITLE or FOOTNOTE statement cancels all titles or
footnotes with higher numbers unless there is code
that defines the higher numbered titles.

Because 1 is less than 4, (4 is the higher number), and
there is no code to execute for title4, title4 is
cancelled.
Defining Titles and Footnotes
PROC PRINT Code
Resultant Title(s)
proc print data=work.march;
title1 'The First Line';
title2 'The Second Line';
run;
proc print data=work.march;
title2 'The Next Line';
run;
proc print data=work.march;
title 'The Top Line';
run;
proc print data=work.march;
title3 'The Third Line';
run;
proc print data=work.march;
title;
run;
22
...
Defining Titles and Footnotes
PROC PRINT Code
proc print data=work.march;
title1 'The First Line';
title2 'The Second Line';
run;
Resultant Title(s)
The First Line
The Second Line
proc print data=work.march;
title2 'The Next Line';
run;
proc print data=work.march;
title 'The Top Line';
run;
proc print data=work.march;
title3 'The Third Line';
run;
proc print data=work.march;
title;
run;
23
...
Defining Titles and Footnotes
PROC PRINT Code
Resultant Title(s)
proc print data=work.march;
title1 'The First Line';
title2 'The Second Line';
run;
The First Line
The Second Line
proc print data=work.march;
title2 'The Next Line';
run;
The First Line
The Next Line
proc print data=work.march;
title 'The Top Line';
run;
proc print data=work.march;
title3 'The Third Line';
run;
proc print data=work.march;
title;
run;
24
...
Defining Titles and Footnotes
PROC PRINT Code
Resultant Title(s)
proc print data=work.march;
title1 'The First Line';
title2 'The Second Line';
run;
The First Line
The Second Line
proc print data=work.march;
title2 'The Next Line';
run;
The First Line
The Next Line
proc print data=work.march;
title 'The Top Line';
run;
The Top Line
proc print data=work.march;
title3 'The Third Line';
run;
proc print data=work.march;
title;
run;
25
...
Defining Titles and Footnotes
PROC PRINT Code
Resultant Title(s)
proc print data=work.march;
title1 'The First Line';
title2 'The Second Line';
run;
The First Line
The Second Line
proc print data=work.march;
title2 'The Next Line';
run;
The First Line
The Next Line
proc print data=work.march;
title 'The Top Line';
run;
The Top Line
proc print data=work.march;
title3 'The Third Line';
run;
The Top Line
The Third Line
proc print data=work.march;
title;
run;
26
...
Defining Titles and Footnotes
PROC PRINT Code
proc print data=work.march;
title1 'The First Line';
title2 'The Second Line';
run;
The First Line
The Second Line
proc print data=work.march;
title2 'The Next Line';
run;
The First Line
The Next Line
proc print data=work.march;
title 'The Top Line';
run;
The Top Line
proc print data=work.march;
title3 'The Third Line';
run;
The Top Line
proc print data=work.march;
title;
run;
27
Resultant Title(s)
The Third Line
Titles
cleared
Exercise
This exercise reinforces the concepts discussed
previously.
28
Exercise - Titles and Footnotes
Produce a listing report of the ia.pilots data set.
1. Change the titles on the first and third lines to be
• title1 International Airlines Pilots
• title3 Alphabetical List
2. Add a footnote to read
Personal Records as of Dec. 1, 2006.
3. After the report is correct, clear the footnote.
29
Exercise - Titles and Footnotes
International Airlines Pilots
Alphabetical List
Obs
IDNum
LName
FName
City
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1333
1739
1428
1404
1118
1905
1407
1410
1439
1545
1777
1106
1442
1478
1556
1890
1107
BLAIR
BOYCE
BRADY
CARTER
DENNIS
GRAHAM
GRANT
HARRIS
HARRISON
HUNTER
LUFKIN
MARSHBURN
NEWKIRK
NEWTON
PENNINGTON
STEPHENSON
THOMPSON
JUSTIN
JONATHAN
CHRISTINE
DONALD
ROGER
ALVIN
DANIEL
CHARLES
FELICIA
CLYDE
ROY
JASPER
SANDRA
JAMES
MICHAEL
ROBERT
WAYNE
STAMFORD
NEW YORK
STAMFORD
NEW YORK
NEW YORK
NEW YORK
MT. VERNON
STAMFORD
BRIDGEPORT
STAMFORD
NEW YORK
STAMFORD
PRINCETON
NEW YORK
NEW YORK
NEW YORK
NEW YORK
State
Gender
CT
NY
CT
NY
NY
NY
NY
CT
CT
CT
NY
CT
NJ
NY
NY
NY
NY
M
M
F
M
M
M
M
M
F
M
M
M
F
M
M
M
M
..................................
30
Personal Records as of Dec. 1, 2006
Exercise - Titles and Footnotes
title1 'International Airlines Pilots';
title3 'Alphabetical List';
footnote 'Personal Records as of Dec. 1, 2006';
proc print data=ia.pilots;
run;
footnote;
31
Exercise - Titles and Footnotes
A representative from Johns Hopkins University is coming
to your school to visit students. You want to be sure that
the students who are interested in attending are notified.


32
Using the schoolchoices data set, produce a list
report of the students who are interested in attending
Johns Hopkins University as either their first, second,
or third choice.
Display only the student’s ID, first name, and last
name, as well as the first through third school choices.
Exercise - Titles and Footnotes
International Airlines Pilots
Alphabetical List
33
Obs
Student
ID
FirstName
Last
Name
firstchoice
45
53
55
57
67
68
98
106
113
4567
5052
5100
5127
5678
5687
8522
9864
9997
Gabriella
Alicia
Paula
Clarissa
Sheila
Terrell
Stephan
Ismael
Tiffany
Crowley
Noboa
Perez
Daly
Dawson
Stires
O'Flynn
Miranda
Pierre
Notre Dame
Tulane University
University of North Carolina - Chapel Hill
Gonzaga University
Columbia University
Johns Hopkins University
Johns Hopkins University
Johns Hopkins University
Johns Hopkins University
Obs
secondchoice
thirdchoice
45
53
55
57
67
68
98
106
113
Johns Hopkins University
Johns Hopkins University
Baylor University
University of Massachusetts System
East Carolina University
Syracuse University
University of Cincinnati
Notre Dame
Gonzaga University
University of Central Florida
Elon University
Johns Hopkins University
Johns Hopkins University
Johns Hopkins University
University of Pennsylvania
Purdue
University of Texas - Austin
Georgia Tech
Exercise - Titles and Footnotes
proc print data=HS.schoolchoice;
var StudentID FirstName Lastname
firstchoice secondchoice thirdchoice;
where firstchoice='Johns Hopkins University' or
secondchoice='Johns Hopkins University' or
thirdchoice='Johns Hopkins University';
run;
34
Exercise - Titles and Footnotes
What titles appeared in your report?
Unless you recently opened SAS, the last title that you set
was at the top of the report. Add relevant titles.


35
Add a title to the top line:
Students interested in Johns Hopkins
Add a title to the second line:
for school visit
Exercise - Titles and Footnotes
Students interested in Johns Hopkins
for school visit
36
Obs
Student
ID
FirstName
Last
Name
firstchoice
45
53
55
57
67
68
98
106
113
4567
5052
5100
5127
5678
5687
8522
9864
9997
Gabriella
Alicia
Paula
Clarissa
Sheila
Terrell
Stephan
Ismael
Tiffany
Crowley
Noboa
Perez
Daly
Dawson
Stires
O'Flynn
Miranda
Pierre
Notre Dame
Tulane University
University of North Carolina - Chapel Hill
Gonzaga University
Columbia University
Johns Hopkins University
Johns Hopkins University
Johns Hopkins University
Johns Hopkins University
Obs
secondchoice
thirdchoice
45
53
55
57
67
68
98
106
113
Johns Hopkins University
Johns Hopkins University
Baylor University
University of Massachusetts System
East Carolina University
Syracuse University
University of Cincinnati
Notre Dame
Gonzaga University
University of Central Florida
Elon University
Johns Hopkins University
Johns Hopkins University
Johns Hopkins University
University of Pennsylvania
Purdue
University of Texas - Austin
Georgia Tech
Exercise - Titles and Footnotes
title 'Students interested in Johns Hopkins';
title2 'for school visit';
proc print data= HS.schoolchoice;
var StudentID FirstName Lastname
firstchoice secondchoice thirdchoice;
where firstchoice='Johns Hopkins University' or
secondchoice='Johns Hopkins University' or
thirdchoice='Johns Hopkins University';
run;
37
Exercise - Titles and Footnotes
The school wants to see students who have a High
School GPA of 3.5 and above.
Modify your program to select only students that meet that
criterion.
1. Be sure to add the GPA column to the report for
verification.
2. Replace the title on the second line with the following:
with at least a 3.5 GPA
3. Save your program as Hopkins_students.sas
to use later.
38
Exercise - Titles and Footnotes
Students interested in Johns Hopkins
with at least a 3.5 GPA
39
Obs
Student
ID
First
Name
Last
Name
HS_GPA
67
68
106
5678
5687
9864
Sheila
Terrell
Ismael
Dawson
Stires
Miranda
3.80
4.00
4.00
Obs
secondchoice
67
68
106
East Carolina University
Syracuse University
Notre Dame
firstchoice
Columbia University
Johns Hopkins University
Johns Hopkins University
thirdchoice
Johns Hopkins University
University of Pennsylvania
University of Texas - Austin
Exercise - Titles and Footnotes
title 'Students interested in Johns Hopkins';
title2 'with at least a 3.5 GPA';
proc print data= HS.schoolchoice;
var StudentID FirstName Lastname
firstchoice secondchoice thirdchoice;
where (firstchoice = 'Johns Hopkins University' or
secondchoice = 'Johns Hopkins University' or
thirdchoice = 'Johns Hopkins University') and
hs_gpa >= 3.5;
run;
40
Adding Labels
By default, SAS uses the variable names as column
headers in the output. Those names might not be very
descriptive and SAS variable names cannot have special
characters other than the underscore.
SAS enable you to add more descriptive text for column
headings, while you preserve the variable name.
41
Assigning Column Labels
General form of the LABEL statement:
LABEL variable='label'
variable='label';
'label'

42
specifies a label up to 256 characters.
The syntax above shows two variables.
You can have one variable or multiple variables.
There is no limit on the number of variables that can
be placed on the LABEL statement. You must follow
the pattern variable = 'label' for each.
Assigning Column Labels
Labels
 are used to replace variable names in SAS output
 do not change the variable names in the data set
 are not global and therefore must be placed inside the
step.
title1 'Salary Report';
proc print data=ia.empdata;
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
run;
43
Assigning Column Labels
title1 'Salary Report';
proc print data=ia.empdata;
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
run;
Why did the labels
not appear?
You coded a
LABEL statement.
Salary Report
44
Obs
Emp
ID
LastName
1
2
3
0031
0040
0071
GOLDENBERG
WILLIAMS
PERRY
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
PILOT
FLTAT
FLTAT
50221.62
23666.12
21957.71
Assigning Column Labels
Remember
To display labels in PROC PRINT, you must
add either a LABEL option or a SPLIT= option in
the PROC PRINT statement.
Most common things that people forget:
 semicolon ( ; )
 LABEL or SPLIT= option in PROC PRINT
45
Assigning Column Labels
Labels are automatically used by many procedures.
PROC PRINT is not one of them.
PROC PRINT requires an option to use labels. The
LABEL statement defines the labels but it does not make
PROC PRINT use the labels.
In the PROC PRINT statement, use one of these options:
 LABEL option
 SPLIT= option
46
Assigning Column Labels
proc print data=ia.empdata label;
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
title1 'Salary Report';
run;
Salary Report
47
Obs
Emp
ID
1
2
3
0031
0040
0071
Last Name
First
Name
Job
Code
Annual
Salary
GOLDENBERG
WILLIAMS
PERRY
DESIREE
ARLENE M.
ROBERT A.
PILOT
FLTAT
FLTAT
50221.62
23666.12
21957.71
Exercise
This exercise reinforces the concepts discussed
previously.
48
Exercise - Labels
Open the program Hopkins_students.sas that
you saved earlier.
Change the column headings so that they appear as
shown below:
Students interested in Johns Hopkins
with at least a 3.5 GPA
49
Obs
Student
ID
First
Name
Last
Name
GPA
First Choice School
67
68
106
5678
5687
9864
Sheila
Terrell
Ismael
Dawson
Stires
Miranda
3.80
4.00
4.00
Columbia University
Johns Hopkins University
Johns Hopkins University
Obs
Second Choice School
67
68
106
East Carolina University
Syracuse University
Notre Dame
Third Choice School
Johns Hopkins University
University of Pennsylvania
University of Texas - Austin
Exercise - Titles and Footnotes
title 'Students interested in Johns Hopkins';
title2 'with at least a 3.5 GPA';
proc print data= HS.schoolchoice label;
var StudentID FirstName Lastname
firstchoice secondchoice thirdchoice;
where (firstchoice='Johns Hopkins University' or
secondchoice='Johns Hopkins University' or
thirdchoice='Johns Hopkins University') and
hs_gpa >= 3.5;
label hs_gpa = 'GPA'
firstchoice = 'First Choice School'
secondchoice = 'Second Choice School'
thirdchoice = 'Third Choice School';
run;
50
Exercise - Titles and Footnotes
Remember
The order of the statements in the PROC PRINT
step does not matter. You can code the LABEL
statement first, last, or in the middle.
You can assign labels in one statement, or have
multiple LABEL statements. Remember to end
each LABEL statement with a semicolon (;) if you
use multiple statements.
51
Exercise - Titles and Footnotes
title 'Students interested in Johns Hopkins';
title2 'with at least a 3.5 GPA';
proc print data= HS.schoolchoice label;
var StudentID FirstName Lastname
firstchoice secondchoice thirdchoice;
where (firstchoice='Johns Hopkins University'
or secondchoice='Johns Hopkins University'
or thirdchoice='Johns Hopkins University')
and hs_gpa >= 3.5;
label hs_gpa = 'GPA';
label firstchoice = 'First Choice School';
label secondchoice = 'Second Choice School';
label thirdchoice = 'Third Choice School';
run;
52
Assigning Column Labels
Remember
To display labels, you must add either a LABEL
option or a SPLIT= option in the PROC PRINT
statement.
What is the SPLIT= option, and how is it different
from the LABEL option?
53
Assigning Column Labels
LABEL Option
 used in the PROC
PRINT statement
54

LABEL statement
defines the labels

tells PROC PRINT to
use the labels
SPLIT= Option
 defines how to split the
label into multiple lines

used in a PROC PRINT
statement with the split
location identified

used instead of the
LABEL option
Assigning Column Labels
LABEL Option - Example
(statement )
makes labels
If you print labels and put
them on your assistant’s
desk, you have your labels
(statement).
Ms. Susan Jones
854 D 34st Street
Oxford, NC 02718
However,…
Unless you tell the assistant
to put them on the
envelopes, they will not be
used (option).
55
Ms. Sue Jones
854 D 34st St.
Dunn, NC 02718
(option)
uses labels
Assigning Column Labels
You saw how to make and use labels with the LABEL
option.
Use the SPLIT= option to control how the labels are
written on the output.
56
Assigning Column Labels
The SPLIT= option
indicates you want labels
displayed in output and
you want to control the
line breaks.
This tells SAS
every time that it
sees a space in
the label to start
a new line.
proc print data=event.prom split=' ';
label lastname='Student Last Name';
run;
proc print data=event.prom split='#';
label lastname='Student#Last#Name';
run;
57
Can be any
character to
mark a new
line. The
result is the
same.
Assigning Column Labels
proc print data=event.prom split=' ';
label lastname='Student Last Name';
run;
Start a new line
58
Obs
Student
ID
1
2
3
4
1005
1154
1155
1245
Student
Last
Name
First
Name
Richardson
Muir
Reisman
Ritter
Chaz
Barbara
Angel
Leticia
Assigning Column Labels
proc print data=ia.empdata split=' ';
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
title1 'Salary Report';
run;
Salary Report
59
Obs
Emp
ID
Last
Name
1
2
3
0031
0040
0071
GOLDENBERG
WILLIAMS
PERRY
First
Name
Job
Code
Annual
Salary
DESIREE
ARLENE M.
ROBERT A.
PILOT
FLTAT
FLTAT
50221.62
23666.12
21957.71
Assigning Column Labels
You are not limited to a space. You can use any
single character that you want.
What if you want to use an asterisk (*) instead?
What would happen?
60
Assigning Column Labels
proc print data=ia.empdata split='*';
label LastName='Last*Name'
FirstName='First*Name'
Salary='Annual*Salary';
title1 'Salary Report';
run;
Salary Report
Obs
Emp
ID
Last
Name
1
2
3
0031
0040
0071
GOLDENBERG
WILLIAMS
PERRY
First
Name
Job
Code
Annual
Salary
DESIREE
ARLENE M.
ROBERT A.
PILOT
FLTAT
FLTAT
50221.62
23666.12
21957.71
Be careful with the character you use.
Notice that the * is removed on the label.
Try this with the letter "a" as the split.
What happens?
61
Exercise
This exercise reinforces the concepts discussed
previously.
62
Exercise
Submit the following code, and replace the letter
'a' in the SPLIT= option.
proc print data=ia.empdata split='a';
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
title1 'Salary Report';
run;
63
Exercise
Salary Report
Obs
1
2
3
4
5
6
7
8
64
Emp
ID
0031
0040
0071
0082
0091
0106
0355
0366
L
st
N
me
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
First
N
me
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
Job
Code
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
Annu
l
S
l
ry
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
Using SAS System Options
You can use SAS system options to change the
appearance of a report.
General form of the OPTIONS statement:
OPTIONS option ...;
The OPTIONS statement
 is not usually included in a PROC or DATA step
 is global.
There are many options. Explore a few popular ones.
65
Using SAS System Options
By default, there is a date and time stamp next to the title
in your output.
This is the date and time that you invoked SAS, not the
current date and time.
Salary Report
26
10:02 Tuesday, September 5, 2006
66
Obs
Emp
ID
Last
Name
1
2
3
4
5
6
7
8
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
First
Name
Job
Code
Annual
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
Using SAS System Options
If you invoked SAS last Thursday and submitted a PROC
PRINT step today, the date on your output would be last
Thursday.
You can change a system option so that your output
displays the current date and time.
67
Using SAS System Options
DATE
(default)
specifies to print the date and time that the
SAS session began at the top of each page
of the SAS output.
NODATE
specifies not to print the date and time that
the SAS session began.
DTRESET specifies to print the current date and time
of the top of each page of SAS output.
To turn off the date and time:
options nodate;
To turn on the date and time:
options date;
68
Exercise
This exercise reinforces the concepts discussed
previously.
69
Exercise - Suppressing the Date
Produce three listing reports of the ia.empdata data
set:
1. Suppress the date on the report.
2. Restore the date.
3. Suppress the date again.
70
Exercise - Suppressing the Date
options nodate;
proc print data=ia.empdata;
run;
options date;
proc print data=ia.empdata;
run;
options nodate;
proc print data=ia.empdata;
run;
71
Exercise - Suppressing the Date
The SAS System
1
Obs
Emp
ID
LastName
FirstName
Job
Code
Salary
1
2
3
4
5
6
7
8
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
The SAS System
2
10:16 Wednesday, September 13, 2006
Obs
Emp
ID
LastName
FirstName
Job
Code
Salary
1
2
3
4
5
6
7
8
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
The SAS System
72
3
Obs
Emp
ID
LastName
FirstName
Job
Code
Salary
1
2
3
4
5
6
7
0031
0040
0071
0082
0091
0106
0355
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
Using SAS System Options
Notice the page numbers in the top-right corner of the
output.
The page numbers accumulate every time that you submit
code that produces output.
There is a system option that you can use to reset the
page number to 1.
73
Using SAS System Options
PAGENO=n specifies a beginning page number (n) for
the next page of SAS output.
To restart page numbers to 1:
options pageno=1;
When you submit a step that produces a report, the report
will start with a page number of 1.
You can choose any starting number.
74
Exercise
This exercise reinforces the concepts discussed
previously.
75
Exercise - Suppressing the Date
Produce a listing report of the ia.empdata data set
starting on page 99.
Reset the page number to 1 and produce the report
again.
76
Exercise - Suppressing the Date
options number pageno=99;
proc print data=ia.empdata;
run;
Salary Report
99
10:02 Tuesday, September 5, 2006
77
Obs
Emp
ID
LastName
1
2
3
4
5
6
7
8
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
Exercise - Suppressing the Date
options number pageno=1;
proc print data=ia.empdata;
run;
Salary Report
1
10:03 Tuesday, September 5, 2006
78
Obs
Emp
ID
LastName
1
2
3
4
5
6
7
8
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
Using SAS System Options
You might not want page numbers to appear on the
output.
SAS has a system option that enables you to suppress
page numbers.
79
Using SAS System Options
NUMBER
(default)
specifies that page numbers be printed
on the first line of each page of output.
NONUMBER specifies that page numbers not be
printed.
To suppress
page numbers
options nonumber;
To restore
page numbers
options number;
SAS continues to increment the page numbers whether they
are displayed or not. When you restore the page numbers,
SAS will display the current page number.
80
Using SAS System Options
If you use the PAGENO= option, you might want to also
use the NUMBER option. If you suppressed page
numbers previously, even though you are using the
PAGENO= option, you need to activate page numbers to
see them.
options number pageno=n;
n
Remember
81
is the beginning page number.
Remember that the page numbers appear
when you submit a step that produces a report,
such as PROC PRINT.
Exercise
This exercise reinforces the concepts discussed
previously.
82
Exercise - Page Numbers
Use the ia.empdata data set to create two listing
reports:
1. Turn the page numbers off and view the output.
2. Change the code to renumber your page number to 1.
3. Verify that the page numbers are active.
83
Exercise - Suppressing the Date
options nonumber;
proc print data=ia.empdata;
run;
Salary Report
10:02 Tuesday, September 5, 2005
84
Obs
Emp
ID
LastName
1
2
3
4
5
6
7
8
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
Exercise - Suppressing the Date
options number pageno=1;
proc print data=ia.empdata;
run;
Salary Report
1
10:02 Tuesday, September 5, 2005
85
Obs
Emp
ID
LastName
1
2
3
4
5
6
7
8
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
Using SAS System Options
There are more ways to customize your output using
system options.
You will see how to control the height and width of the
output.
86
Using SAS System Options
LINESIZE= changes the width of your output, or how
many characters can fit on one line of output.
LINESIZE=n specifies the number of characters that
fits on one line for the SAS log and SAS
LS=n
output.
Line Size = Width
Example:
Use either one.
options ls=90;
87
options linesize=90;
Using SAS System Options
PAGESIZE= changes the height of your output, or the
number of lines that you can fit into one page of output.
PAGESIZE=n specifies the number of lines (n)
that can be printed per page of
PS=n
SAS output.
options ps=60;
Use either one.
options pagesize=60;
88
Page Size = Height
Example:
Exercise
This exercise reinforces the concepts discussed
previously.
89
Exercise - Page Width and Height
Produce a list report of the ia.empdata data set.
1. Change the width to 62 and the height to 95.
2. Set the starting page number to 800.
3. Suppress the time and date.
90
Exercise - Page Width and Height
options nodate number pageno=800;
options ls=62 ps=95;
proc print data=ia.empdata;
run;
Salary Report
91
Obs
Emp
ID
LastName
1
2
3
4
5
6
7
8
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
800
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
Review
Selected SAS system options:
DATE
(default)
specifies to print the data and time that
the SAS session began at the top of
each page of the SAS output.
NODATE
specifies not to print the date and time
that the SAS session began.
LINESIZE=n
LS=n
specifies the line size for the SAS log
and SAS output.
PAGESIZE=n specifies the number of lines (n) that
PS=n
can be printed per page of SAS output.
92
Review
Selected SAS system options:
NUMBER
(default)
specifies that page numbers be printed
on the first line of each page of output.
NONUMBER specifies that page numbers not be
printed.
PAGENO=n
specifies a beginning page number (n)
for the next page of SAS output.
Example:
options nodate nonumber ls=72;
93
Exercise
This exercise reinforces the concepts discussed
previously.
94
Exercise
View the data set named SATscores. Your instructor
will tell you where the data set is stored.
Write appropriate code to produce the report in the
format on the next slide.
95
College Application Analysis
1
Apex High School Senior Class 2003
Student
ID
Number
First
SAT
Score
Second
SAT
Score
Freshman
GPA
College
Applications
High
School
GPA
1005
1154
1155
1245
1257
1258
1266
2001
2006
2046
2055
2334
2335
2561
2584
2587
2600
2606
2681
2689
3030
3032
1270
1220
1160
950
1070
1110
1220
1150
1440
850
1280
1020
880
1080
1200
1120
970
1210
1030
1020
1400
720
1313
1263
1203
993
1113
1153
1263
1193
1483
893
1323
1063
923
1123
1243
1163
1013
1253
1073
1063
1443
763
3.18
3.33
3.25
2.42
2.63
2.91
2.83
2.51
3.82
2.54
3.38
3.02
2.6
3.81
3.02
3.48
2.15
3.8
3.13
3.4
3.59
1.62
3
2
5
7
6
4
3
2
5
5
4
5
3
9
10
4
6
2
3
3
3
4
3.4
4
3.75
3.75
4
4
2.8
3.8
4
2.6
3.75
3.75
2.8
3.75
3.5
3.75
3.2
4
3.75
4
4
3.25
From student self report 2003
96
Section 5.2
Formatting Data Values
Objectives



98
Display formatted values using SAS formats in a list
report.
Create user-defined formats using the FORMAT
procedure.
Apply user-defined formats to variables in a list report.
SAS Vocabulary









99
FORMAT
<$>format<w>.<d>
w.d
$w.
COMMAw.d
DOLLARw.d
MMDDYYw.
DATEw.
PROC FORMAT
Formatting Data Values
You can enhance reports by using SAS formats to format
data values.
SAS Data Set
LastName
FirstName
Age
TORRES
LANGKAMM
SMITH
WAGSCHAL
TOERMOEN
JAN
SARAH
MICHAEL
NADJA
JOCHEN
23
46
71
37
16
Format
LastName
TORRES
LANGKAMM
SMITH
WAGSCHAL
TOERMOEN
FirstName
JAN
SARAH
MICHAEL
NADJA
JOCHEN
Values in the SAS data set are not changed.
100
Report
SAS Formats
There are many formats in SAS, divided into different
categories such as numeric, date/time, and character
formats.
You can also create your own formats, which is discussed
later in the course.
In this section, you explore several different formats.
102
Using SAS Formats
You can enhance the readability of reports by formatting
the data values.
Salary Report
103
Obs
Emp
ID
Last
Name
1
2
3
4
5
6
7
8
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
First
Name
Job
Code
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
Annual
Salary
$50,221.62
$23,666.12
$21,957.71
$96,387.39
$32,278.40
$24,161.14
$59,803.16
$120,202.38
Formatting Data Values
To apply a format to a specific SAS variable, use the
FORMAT statement.
General form of the FORMAT statement:
FORMAT variable(s) format;
Example:
proc print data=ia.empdata;
format Salary dollar11.2;
run;
104
Formatting Data Values
• dollar indicates
Example:
that you want a $
and commas.
proc print data=ia.empdata noobs;
• 11 is the total display
format Salary dollar11.2;
width in the output
run;
(including $ , .).
• 2 is the number of
decimal places.
The SAS System
105
Emp
ID
Last
Name
0031
0040
0071
0082
0091
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
First
Name
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
Job
Code
PILOT
FLTAT
FLTAT
PILOT
FLTAT
Annual
Salary
$50,221.62
$23,666.12
$21,957.71
$96,387.39
$32,278.40
What Is a SAS Format?
A format is an instruction that SAS uses to write data
values. SAS formats have the following form:
Indicates a
character
format (Use
<$>format<w>.<d>
Number of
decimal places
for numeric data
only if data is
character.)
Format name
Total width (including
decimal places and
special characters)
106
Required
delimiter
The dot
indicates a
format.
What Is a SAS Format?
Most common things people forget:
 semicolon (;)
 LABEL (or SPLIT=) option in PROC PRINT
 the dot (.) delimiter on the format name
<$>format<w>.<d>
Required
delimiter
The dot
indicates a
format.
107
SAS Formats
Examples of SAS formats:
w.d
8.2
(width.decimal)
standard numeric format
Width=8, 2 decimal places
99999.99
1 2 3 4 5 6 7 8
$w.
$5.
($width)
standard character format
Width=5
108
KATHY
1 2 3 4 5
SAS Formats
Other SAS formats:
COMMAw.d
COMMA9.2 (comma width.decimal)
Commas in a number
Width=9, 2 decimal places 99,999.99
1 2 3 4 5 6 7 8 9
DOLLARw.d
DOLLAR10.2 (dollar width.decimal)
Dollar signs and commas in a number
Width=10, 2 decimal places $99,999.99
1 2 3 4 5 6 7 8 9 10

109
The widths include the dollar signs, commas, decimal point,
and decimal digits.
Review
Selected SAS formats:
w.d
8.2
Standard numeric format
Width=8, 2 decimal places:
12234.21
$w.
$5.
standard character format
Width=5:
KATHY
COMMAw.d
COMMA9.2
commas in a number
Width=9, 2 decimal places:
12,234.21
DOLLARw.d dollar signs and commas in a number
DOLLAR10.2 Width=10, 2 decimal places: $12,234.21
110
SAS Formats
Compare the stored value with the formatted, or displayed
value.
Stored Value
27134.2864
27134.2864
27134.2864
Format
COMMA12.2
12.2
DOLLAR12.2
Displayed Value
27,134.29
27134.29
$27,134.29
What if the width in the format were not large enough to
display the entire value?
111
SAS Formats
Stored Value
27134.2864
Format
Displayed Value
DOLLAR12.2
The 12 is the total columns in the
display, including two decimal places.
$27,134.29
SAS rounds
the decimals
from 4 to two.
SAS needs only 10 columns to display the value. You
requested 12, so you have two blank spaces in front of
the value because numbers are right-aligned.
112
SAS Formats
Given the previous example, 10 is the minimum width you
need to display the value.
What happens if the width is too small?
Stored Value
27134.2864
27134.2864
Format
DOLLAR12.2
DOLLAR9.2
Displayed Value
$27,134.29
$27134.29
SAS has only nine columns to display the value. The
priority is to preserve the numeric value. Because the
comma is not part of the real number, it is dropped from
the display.
113
SAS Formats
What happens if you make the width 8?
Stored Value
27134.2864
27134.2864
27134.2864
Format
DOLLAR12.2
DOLLAR9.2
DOLLAR8.2
Displayed Value
$27,134.29
$27134.29
27134.29
SAS has only eight columns to display the value.
The priority is to preserve the numeric value. Because the
comma and the dollar sign are not part of the real number,
they are dropped from the display.
114
SAS Formats
What happens if you make the width smaller than the
value?
Stored Value
27134.2864
27134.2864
27134.2864
27134.2864
Format
DOLLAR12.2
DOLLAR9.2
DOLLAR8.2
DOLLAR5.2
Displayed Value
$27,134.29
$27134.29
27134.29
27134
There are only five columns to display the value. To
preserve the integrity of the number, SAS drops the
comma, the dollar sign, and the decimal, and rounds to
the nearest whole number.
115
SAS Formats
What if you make the width even smaller?
Stored Value
27134.2864
27134.2864
27134.2864
27134.2864
27134.2864
Format
DOLLAR12.2
DOLLAR9.2
DOLLAR8.2
DOLLAR5.2
DOLLAR4.2
Displayed Value
$27,134.29
$27134.29
27134.29
27134
27E3
SAS displays the number in exponential notation 27 x 103
and the displayed number loses precision. The stored
values remain unchanged.
116
SAS Formats
What if you apply a format that is too small for
the number to be displayed in scientific
notation?
117
SAS Formats
If the width is too small for exponential notation, SAS
displays asterisks.
Stored Value
27134.2864
27134.2864
27134.2864
27134.2864
27134.2864
27134.2864
27134.2864
27134.2864
118
Format
COMMA12.2
12.2
DOLLAR12.2
DOLLAR9.2
DOLLAR8.2
DOLLAR5.2
DOLLAR4.2
DOLLAR3.2
Displayed Value
27,134.29
27134.29
$27,134.29
$27134.29
27134.29
27134
27E3
***
Formatting Data Values
proc print data=ia.empdata split=' ';
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
format Salary dollar11.2;
title1 'Salary Report';
run;
Salary Report
119
Obs
Emp
ID
Last
Name
1
2
3
0031
0040
0071
GOLDENBERG
WILLIAMS
PERRY
First
Name
Job
Code
DESIREE
ARLENE M.
ROBERT A.
PILOT
FLTAT
FLTAT
Annual
Salary
$50,221.62
$23,666.12
$21,957.71
Formatting Data Values
If you do not want to display decimals, use the
DOLLAR11. or the DOLLAR11.0 format.
proc print data=ia.empdata split=' ';
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
format Salary dollar11.;
title1 'Salary Report';
run;
Salary Report
120
Obs
Emp
ID
Last
Name
1
2
3
0031
0040
0071
GOLDENBERG
WILLIAMS
PERRY
First
Name
Job
Code
Annual
Salary
DESIREE
ARLENE M.
ROBERT A.
PILOT
FLTAT
FLTAT
$50,221
$23,666
$21,957
Formatting Data Values
What happens if you forget to put the . after the
format name ?
proc print data=ia.empdata split=' ';
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
format Salary dollar11 ;
title1 'Salary Report';
run;
121
continued...
Formatting Data Values
You got output, although you forgot the period.

122
Emp
ID
LastName
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
FirstName
Job
Code
Salary
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
The decimals were already stored in the data.
Formatting Data Values
Read the messages in your SAS Log.
Partial Log
32
proc print data=ia.empdata noobs;
33
format salary dollar11;
WARNING: Variable DOLLAR11 not found in data set IA.EMPDATA.
34
run;
SAS thinks that there is a variable called DOLLAR11 in
the data set ia.empdata.
The dot indicates to SAS that this is a format, not a
variable name.
123
SAS Formats
Recall that a SAS date is stored as the number of days
between 01JAN1960 and the specified date.
SAS date formats display SAS date values in standard
date forms.
For example: 14JAN2008 or 05/18/2008
124
SAS Formats
Selected SAS date formats:
MMDDYYw.
Displays the date in the form of two digits for the month,
and two digits for the day, followed by the year.
What is displayed depends on the width that you choose.
Format
MMDDYY6.
MMDDYY8.
MMDDYY10.
125
Displayed
Value
101601
10/16/01
10/16/2001
 There is no
MMDDYYYY format.
A four-digit year is
represented by
MMDDYY10.
SAS Formats
DATEw.
Displays the date in the form of two digits for the day, a
three-character string for the month, followed by two or
four digits for the year.
What is displayed depends on the width that you choose.
Format
DATE7.
DATE9.
126
Displayed
Value
16OCT01
16OCT2001
SAS Formats
More Examples:
Stored
Format
Value
0 MMDDYY8.
127
0
MMDDYY10.
1
DATE9.
Displayed Value
01/01/60
01/01/1960
02JAN1960
-1
WORDDATE.
December 31, 1959
365
DDMMYY10.
31/12/1960
366
WEEKDATE.
Sunday, January 1, 1961
Formats
You can use one FORMAT statement or
multiple FORMAT statements.
Remember
End each of the FORMAT statements with the
semicolon (;).
128
Formats
The Sales_emps data set contains the Salary,
Total Sales, and Commission values for each
Sales Employee.
Produce a listing report of the data set. Format Salary,
TotalSales, and Commission. Use the
DOLLAR14.2 format.
You can do this a few different ways.
129
Formats
Produce a listing report of the data set. Format Salary,
TotalSales, and Commission. Use the
DOLLAR14.2 format.
Method One
List each variable in its own FORMAT statement.
proc print data=ia.sales_emps;
format Salary dollar14.2;
format TotalSales dollar14.2;
format Commission dollar14.2;
run;
130
Formats
Produce a listing report of the data set. Format Salary,
TotalSales, and Commission. Use the
DOLLAR14.2 format.
Method Two
Format them all in one FORMAT statement.
proc print data=ia.sales_emps;
format Salary dollar14.2
TotalSales dollar14.2
Commission dollar14.2;
run;
131
Formats
Method Three
Format them together all on one FORMAT statement.
Because you use the same format for all three columns,
you can list the variables after the keyword FORMAT,
followed by the DOLLAR14.2 format.
proc print data=ia.sales_emps;
format Salary
TotalSales
Commission dollar14.2;
run;
132
Formats
proc print data=ia.sales_emps;
format Salary
TotalSales
Commission dollar14.2;
run;
SAS sees the keyword FORMAT and then expects a
variable name after the keyword. Any variable between
the keyword FORMAT and the name of a format will
have the DOLLAR14.2 format applied.
The dot indicates a format name.
Remember
133
Formats
You can add more variables to format to the statement.
There is no limit to the number of variables you can list in
a FORMAT statement.
proc print data=ia.sales_emps;
format HireDate mmddyy10.
Salary
TotalSales
Commission dollar14.2;
run;
134
Exercise
This exercise reinforces the concepts discussed
previously.
135
Exercise
Create a listing report of the state_income
data set.
Format the data so that the median incomes for
2004 and 2005 are displayed with dollar signs,
commas, and no decimal places.
In addition, the change in income should be
displayed with commas and one decimal place.
136
Exercise
One Solution:
proc print data=mydata.state_income;
format median2004 median2005 dollar9.
income_change comma8.1;
run;
137
Exercise
Partial Output
Obs
1
2
3
4
5
6
7
8
138
State
Alabama
Alaska
Arizona
Arkansas
California
Colorado
Connecticut
Delaware
median2004
median2005
$38,695
$55,957
$44,499
$35,058
$51,593
$52,792
$57,636
$50,838
$37,502
$56,398
$45,279
$36,406
$51,312
$51,518
$56,889
$50,445
income_
change
-1,193.0
440.0
779.0
1,348.0
-281.0
-1,274.0
-747.0
-392.0
Exercise
The output of
ia.sales_emps
has many blank
spaces.
Format the data to
produce a report
similar to this partial
output.
139
Exercise
1. Reduce the amount of spacing between columns by
setting the line size to 90.
2. Suppress the date and page number.
3. Add a title Sales Employees.
4. Format hiredate to display as mm/dd/yyyy.
5. Format Salary, Total Sales, and
Commission to show dollar signs with a width of 14
columns and two decimal places.
6. Format FirstName, LastName, and Country
for a width of 12 character columns.
140
Exercise
One Solution:
options ls=90 nodate nonumber;
title 'Sales Employees';
proc print data=apex.sales_emps;
format HireDate mmddyy10.
Salary
TotalSales
Commission dollar14.2
LastName FirstName Country $12.;
run;
141
Creating User-Defined Formats
SAS provides many different formats.
However, these formats might not work for all of your
data.
For example, there is no gender format to code M to Male
and F to Female.
You can create custom formats using the FORMAT
procedure.
142
Creating User-Defined Formats
To create and use custom formats:
1. Use the FORMAT procedure to create the format.
2. Apply the format to specific variable(s) by using a
FORMAT statement.
143
Creating User-Defined Formats
General form of a PROC FORMAT step:
PROC FORMAT;
VALUE format-name range1='label '
range2='label '
... ;
RUN;
The PROC FORMAT statement tells SAS that you want to
create a format.
The VALUE statement defines the format that you want to
create.
144
Creating User-Defined Formats
General form of a PROC FORMAT step:
PROC FORMAT;
VALUE format-name range1='label '
range2='label '
...
;
RUN;

145
The semicolon is at the end of the VALUE statement,
not after each label.
Creating User-Defined Formats
General form of a PROC FORMAT step:
Notice that there is no DATA=
option and no data set name.
PROC FORMAT;
VALUE format-name range1='label '
range2='label '
...;
RUN;
146
What is actually
in the data
What you want the
value to appear as
For example, 500-600
or a single value 500
For example,
Graduate Courses
Creating User-Defined Formats
Labels
 can be up to 32,767 characters in length
 are typically enclosed in quotation marks, although it is
not required. (It is good practice to do so.)
Range(s)
 can be single values
 can be ranges of values.
147
Creating User-Defined Formats
Format-name
 names the format that you are creating
 cannot be more than 32 characters in SAS®9
 cannot be the name of a SAS format (for example,
COMMAw.d).
148
Creating User-Defined Formats
There are more rules for format names.
Character
$
You can have
up to 32
characters in a
name; 8 are
shown here.
Numeric
For character values, the format name must have both of
the following:
 a dollar sign ($) as the first character
 a letter or underscore as the second character
149
Creating User-Defined Formats
There are more rules for format names.
Character
$
You can have
up to 32
characters in a
name; 8 are
shown here.
Numeric
For numeric values, the format name must have a letter or
underscore as the first character.
150
Creating User-Defined Formats
There are more rules for format names.
Character
$
You can have
up to 32
characters in a
name; 8 are
shown here.
Numeric
For both character and numeric data, formats
 cannot end in a number
 cannot end in a period.
151
Creating User-Defined Formats
There are more rules for format names.
Character
$
You can have
up to 32
characters in a
name; 8 are
shown here.
Numeric
Anything in between can be letters, numbers, or
underscores, but no special characters.
152
Review
Rules for Format-name:
 Names the format you are creating
 Cannot be more than 32 characters in SAS®9
 For character values, must have a
– dollar sign ($) as the first character
– letter or underscore as the second character
 For numeric values, must have a letter or
underscore as the first character
 Cannot end in a number
 Cannot have the same name as a SAS format
 Does not end with a period in the VALUE statement
153
Creating User-Defined Formats
Assign labels to single numbers.
proc format;
value gender 1='Female'
2='Male';
run;
Numeric
format name
Numeric data value:
What is stored in the data
154
Formatted
value:
how you
want the
value to
appear in
the output
Creating User-Defined Formats
How does SAS know that the format GENDER is a
numeric format?
Which answer do you think is correct?
A) SAS sees the number 1 after the name.
B) The name gender does not begin with a $.
C) SAS reads the data.
proc format;
value gender 1='Female'
2='Male';
run;
155
...
Creating User-Defined Formats
The correct answer is B. If gender were a character
format, it would begin with a $.
A) SAS sees the number 1 after the name.
B) The name gender does not begin with a $.
C) SAS reads the data.
A is incorrect because SAS does not require quotation
marks around the value. SAS does not know if it is a
character "1" or a numeric 1.
156
...
Creating User-Defined Formats
The correct answer is B. If gender were a character
format, it would begin with a $.
A) SAS sees the number 1 after the name.
B) The name gender does not begin with a $.
C) SAS reads the data.
C is incorrect because the format is created in this
procedure. You did not apply it to the data.
157
Creating User-Defined Formats
What if there were a data value other than a 1 or a 2?
OTHER is a special keyword that you can use for values
that occur outside the defined range.
proc format;
value gender 1='Female'
2='Male'
other='Miscoded';
run;
Keyword
158
Creating User-Defined Formats
Assign labels to ranges of numbers.
proc format;
value boardfmt 0-49='Below'
50-99='Average'
100-200='Above Average';
run;
Numeric data ranges
159
Creating User-Defined Formats
As with the OTHER keyword, there are LOW and HIGH
keywords, which are useful when you do not know the
endpoints or the endpoints change in the data.
proc format;
value boardfmt low-49='Below'
50-99='Average'
100-high='Above Average';
run;
160
Creating User-Defined Formats
Assign labels to character values and ranges of character
values.
Character
format name
proc format;
value $grade 'A'='Good'
'B'-'D'='Fair'
'F'='Poor'
'I','U'='See Instructor'
other='Miscoded';
run;
Character
value range
161
Discrete
character
values
Keyword
Creating User-Defined Formats
You used SAS formats to change the appearance of
output. You also created user-defined formats.
You now need to apply those user-defined formats to the
data to change the appearance in the output.
You must create the format and then apply the
format to the data with a FORMAT statement.
Remember
162
Creating User-Defined Formats
To create and use your own
formats:
1. Use the FORMAT
procedure to create the
format
2. Tell SAS to apply the
formats that you created
by using a FORMAT
statement.
(This is the same statement you
learned about in the previous
section.)
163
(Procedure)
makes formats
Ms. Susan Jones
854 D 34st Street
Oxford, NC 02718
Ms. Sue Jones
854 D 34st St.
Dunn, NC 02718
(Statement)
uses formats
Using User-Defined Formats
Create your own formats to recode data values in a
report.
Salary Report in Categories
164
Emp
ID
Last
Name
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
First
Name
JobCode
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
Pilot
Flight
Flight
Pilot
Flight
Flight
Pilot
Pilot
Attendant
Attendant
Attendant
Attendant
Annual
Salary
More than
Less than
Less than
More than
25,000 to
Less than
More than
More than
50,000
25,000
25,000
50,000
50,000
25,000
50,000
50,000
Creating User-Defined Formats
Step 1: Create the format.
proc format;
value $codefmt 'FLTAT'='Flight Attendant'
'PILOT'='Pilot';
run;
Step 2: Apply the format
You must end the
proc print data=ia.empdata;
format name with a
format JobCode $codefmt.;
dot when you
run;
apply the format.
165
Applying User-Defined Formats
proc print data=ia.empdata split=' ' noobs;
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
format Jobcode $codefmt.;
title1 'Salary Report in Categories';
run;
Salary Report in Categories
166
Emp
ID
Last
Name
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
First
Name
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
JobCode
Pilot
Flight
Flight
Pilot
Flight
Flight
Pilot
Pilot
Attendant
Attendant
Attendant
Attendant
Annual
Salary
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
Creating User-Defined Formats
What would be displayed for a value of 49.5?
a) Below
b) Average
c) 49.5
proc format;
value boardfmt low-49='Below'
50-99='Average'
100-high='Above Average';
run;
167
Creating User-Defined Formats
What would the output look like for a grade of 49.5?
c) 49.5
Because 49.5 does not fit exactly into any range, SAS
displays the value as it is stored in the SAS data set.
proc format;
value boardfmt low-49='Below'
50-99='Average'
100-high='Above Average';
run;
168
Creating User-Defined Formats
For continuous ranges of numeric values, you can use the
< symbol next to the hyphen.
The < indicates that all numbers up to and not including
that value are included in the range.
Low-<50 includes all numbers from the lowest value to
49.99, or the highest number less than 50.
proc format;
value boardfmt low-<50='Below'
50-100='Average'
100<-high='Above Average';
run;
169
Using User-Defined Formats
This is the report that you want to create with formatted or
recoded data values.
Salary Report in Categories
170
Emp
ID
Last
Name
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
First
Name
JobCode
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
Pilot
Flight
Flight
Pilot
Flight
Flight
Pilot
Pilot
Attendant
Attendant
Attendant
Attendant
Annual
Salary
More than
Less than
Less than
More than
25,000 to
Less than
More than
More than
50,000
25,000
25,000
50,000
50,000
25,000
50,000
50,000
Creating User-Defined Formats
Step 1: Create the format
proc format;
value money low-<25000 ='Less than 25,000'
25000-50000='25,000 to 50,000'
50000<-high='More than 50,000';
run;
Step 2: Apply the format
proc print data=ia.empdata;
format Salary money.;
run;
171
Creating User-Defined Formats
You can use multiple VALUE statements in a single
PROC FORMAT step.
proc format;
value $codefmt 'FLTAT'='Flight Attendant'
'PILOT'='Pilot';
value money low-<25000 ='Less than 25,000'
25000-50000='25,000 to 50,000'
50000<-high='More than 50,000';
run;
172
Applying User-Defined Formats
proc print data=ia.empdata split=' ' noobs;
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
format Jobcode $codefmt. Salary money.;
title1 'Salary Report in Categories';
run;
Salary Report in Categories
173
Emp
ID
Last
Name
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
First
Name
JobCode
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
Pilot
Flight
Flight
Pilot
Flight
Flight
Pilot
Pilot
Attendant
Attendant
Attendant
Attendant
Annual
Salary
More than
Less than
Less than
More than
25,000 to
Less than
More than
More than
50,000
25,000
25,000
50,000
50,000
25,000
50,000
50,000
Exercise – Section 5.2
This exercise reinforces the concepts discussed
previously.
174
Section 5.3
Creating HTML Reports
Objectives

176
Create HTML reports using the Output Delivery
System (ODS).
The Output Destination
You improved the appearance of the output, but you can
do more.
By default, SAS sends output to the Output window.
You can use the Output Delivery System to send the
output to an HTML file.
177
Business Task
You want to take the output that you created in the
previous section and display it in HTML form.
178
The Output Delivery System (ODS)
Use the Output Delivery
System (ODS) to easily create
the output in the form that you
want.
ODS always runs in the
background. It directs the
output generated to the correct
destination.
By default, the Output window is an open destination.
When you submitted the code that produced reports, ODS
sent it to the Output window.
179
The Output Delivery System (ODS)
ODS statements enable you to create output in a variety
of forms.
ODS
SAS Output
Window
HTML
SAS
Report
File
Printer
Other
180
The Output Delivery System (ODS)
You can output to the following:
 HTML file
 PDF file
 RTF file (Microsoft Word)
 and more…
181
The Output Delivery System (ODS)
Outputting a report in HTML enables you to post the data
on the Web or to send it via e-mail.
ODS requires two statements around the code that
produces a report (or reports): an OPEN statement and a
CLOSE statement.
182
Generating HTML Files
The ODS HTML statement opens, closes, and manages
the HTML destination.
General form of the ODS HTML statement:
ODS HTML FILE='HTML-file-specification' <options>;
SAS code that generates output
ODS HTML CLOSE;
Make sure that your step boundary appears before the
ODS CLOSE statement.
183
Generating HTML Files
Output is directed to the specified HTML file until you
 close the HTML destination
 specify another destination file.
HTML File
ods html file='…';
report
proc print…
proc means…
report
proc freq…
ods html close;
report
184
Creating an HTML Report
1. Open an HTML destination for the listing report.
2. Generate the report.
3. Close the HTML destination.
ods html file='filename.html';
proc print data=ia.empdata label noobs;
label Salary='Annual Salary';
format Salary money. Jobcode $codefmt.;
title1 'Salary Report';
run;
ods html close;

185
Because you did not put a path in front of the filename, SAS
creates the HTML file in the current working directory.
Creating an HTML Report
186
Creating a PDF Report
To create a PDF file, change all references of HTML to
PDF.
ods pdf file='filename.pdf ';
proc print data=ia.empdata label noobs;
label Salary='Annual Salary';
format Salary money. Jobcode $codefmt.;
title1 'Salary Report';
run;
ods pdf close;
187
Creating an RTF Report
To create an RTF file, change the references in the ODS
statements from PDF to RTF. Change the file extension to
.doc or .txt.
ods rtf file='filename.doc ';
proc print data=ia.empdata label noobs;
label Salary='Annual Salary';
format Salary money. Jobcode $codefmt.;
title1 'Salary Report';
run;
ods rtf close;
188
Creating an HTML Report
This is the default HTML style. ODS has many templates
to change colors and fonts.
189
The Output Delivery System (ODS)
You can find the styles by clicking in the Results window
(left side of the SAS window).
 Select View Menu.
 Select Templates and a new window opens.

Expand Sashelp.Tmplmst and select the
STYLES folder.
You can see a list of styles on the right side of the
window.
190
Creating an HTML Report
Add the STYLE= option to the ODS OPEN statement with
the style that you want to use.
ods html file='filename.html' style=watercolor;
proc print data=ia.empdata label noobs;
label Salary='Annual Salary';
format Salary money. Jobcode $codefmt.;
title1 'Salary Report';
run;
ods html close;
191
Creating an HTML Report
192