You are on page 1of 24

SASTechies

info@sastechies.com
http://www.sastechies.com
 Creating

◦ SAS Tables,
◦ Listings,
◦ Basic Statistics Procedures with
SAS TLG’s
◦ Graphs
◦ ODS HTML
◦ Proc Report and Other Utility
Procedures

SAS Techies 2009 11/02/21 2


◦ Using the SAS Output
Delivery System (ODS),
you can create,
customize, and manage
HTML output in any
operating environment
by submitting
programming
statements.

SAS Techies 2009 11/02/21 3


◦ ODS creates your output in the
form of output objects.
Each output object contains the
results of a procedure or DATA
step (the data component) and
may also contain information
about how to render the results
(the table definition).

◦ ODS sends the output object to


the destination(s) you specified
and creates SAS data sets,
listing output, or HTML output
as appropriate.

SAS Techies 2009 11/02/21 4


◦ ODS creates a link to
each output object in
the Results window and
identifies each output
object by the
appropriate icon.

SAS Techies 2009 11/02/21 5


 By default, the Listing
destination is open

Use
ods listing close; - to close
ods listing; - to open
 the Output and HTML

destinations are closed.

ods html; - to open


Out=data options invokes the
output dest.

SAS Techies 2009 11/02/21 6


 ODS HTML
        HTML-file-specification(s) 
<option(s)>; where
◦ HTML-file-specification(s) opens the HTML
destination and specifies the file to write
to. The file remains open until you either
specify a new file or close the HTML
destination by submitting this form of the
ODS HTML statement:
     ODS HTML CLOSE;
The specifications for these files can be the
following:

◦ BODY=file-specification
 identifies the file that contains the
HTML output.
◦ FRAME=file-specification
◦ CONTENTS=file-specification
 identifies the file that integrates the table  identifies a table of contents that links
of contents, the page contents, and the to the body file.
body file. If you specify FRAME=, you must
specify CONTENTS= or PAGE= or both.
◦ PAGE=file-specification
 identifies the file that contains a
description of each page of the body
file and links to the body file.

SAS Techies 2009 11/02/21 7


ods listing close;
ods html body='c:\records\data.html'
contents='c:\records\toc.html'
frame='c:\records\frame.html';

proc print data=clinic.admit label;


var sex age height weight actlevel;
label actlevel='Activity Level'; run;

proc print data=clinic.stress2;


var id resthr maxhr rechr; run; ◦ Below each heading is a link to the body
file by a procedure. Select a link in the
ods html close; ods listing; table of contents to display the
corresponding body file.

SAS Techies 2009 11/02/21 8


URL= suboption in a file
specification: HTML-file-
specification(URL=' Uniform- ◦ Uniform-Resource-Locator
Resource-Locator') where provides a URL for HTML-file-
specification. ODS uses this URL
instead of the file name in all
◦ HTML-file-specification opens the links and references that it
the HTML destination and creates that point to the file.
specifies the file to write to. Use
the URL= suboption in any ODS
file specification except FRAME= ◦ URL= is useful for building
(because no ODS file references HTML files that may be moved
the frame file). from one location to another. If
the links from the contents and
page files are constructed with a
simple URL (one name), they
work as long as the contents,
page, and body files are all in
the same location.

SAS Techies 2009 11/02/21 9


◦ Relative URLs In this
ODS HTML statement,
URL= specifies simple
URLs (one name).
These files must be
stored in the same
location.

ods html body='c:\records\data.html'


(url='data.html')
contents='c:\records\toc.html'
(url='toc.html')
frame='c:\records\frame.html';

SAS Techies 2009 11/02/21 10


you want to display these  Absolute URLs Alternately, in this
ODS HTML statement, the URL=
files from a Web server. suboptions specify complete URLs
using the HTTP protocol. These
files can be stored in the same or
different locations.

ods html body='c:\records\data.html'


(url='http://mysite.com/myreports/data.ht
ml’)
contents='c:\records\toc.html'
(url='http://mysite.com/mycontents/toc.ht
ml') frame='c:\records\frame.html';

SAS Techies 2009 11/02/21 11


O S A D ◦ STYLE=style-name where style-name is
I Hei Wei ActL Fe the name of a valid SAS or user-defined
b Name e g at
D ght ght evel e style definition.
s x e e
◦ Don't enclose style-name in quotation
1
24 Murray,
M 27 1 72 168 HIGH
85. marks.
58 W 20

2
24
Almers, C F 34 3 66 152 HIGH
124 ods listing close;
62 .80
ods html
3
25 Bonavent
F 31 17 61 123 LOW
149 body='c:\records\data.html'(url='data.html')
01 ure, T .75 contents='c:\records\toc.html'(url='toc.html‘)
25 Johnson, 149 frame='c:\records\frame.html'
4 F 43 31 63 137 MOD
23 R .75 style=beige;
25 LaMance, 124 proc print data=clinic.admit label; var id sex
5
39 K
M 51 4 71 158 LOW
.80 age height weight actlevel; label
actlevel='Activity Level'; run;
6
25
Jones, M M 29 6 76 193 HIGH
124 proc print data=clinic.stress2; var id resthr
44 .80 maxhr rechr; run;
25 Reberson 149 ods html close; ods listing;
7 F 32 9 67 151 MOD
52 ,P .75
25 149
8 King, E M 35 13 70 173 MOD
55 .75
25 124
9 Pitts, D M 34 22 73 154 LOW
63 .80
25 Eberhardt 124
10 F 49 27 64 172 LOW
68 ,S .80

SAS Techies 2009 11/02/21 12


ods listing close;  When you use the PATH=
ods html path='c:\records'(url=none) option, you don't need to
body='data.html' specify the full path name for
contents='toc.html' the body, contents, or frame
frame='frame.html'; files.
style=brick;
PATH=file-specification 
ods html path=  <(URL='Uniform-Resource-
'http://mysite.com/myreports/’ Locator' | NONE)>
(url=none)
body='data.html'
contents='toc.html'
frame='frame.html';
style=brick;

SAS Techies 2009 11/02/21 13


Laguardia Flights by
Destination
/ style={background=lib}
font_style=italic} ;
and Revenue,
  March 4-10
Min Max Mean Sum   Min Max Mean Sum
Destination   Destination  
Copenhagen Boarded 81 154 131 Copenhagen
786 Boarded 81 154 131 786
Transferre Transferred 5 21 13 75
d 5 21 13 75
Deplaned 103 177 147 881
Deplaned 103 177 147 881
Revenue 109,885 196,540 139,951 839,705
Revenue 109,885 196,540 139,951 839,705
Frankfurt Boarded 129 210 170 1,190
Frankfurt Boarded 129 210 170 1,190
Transferred 5 22 13 91
Transferre
d 5 22 13 91
Deplaned 147 237 188 1,314

Deplaned 147 237 188 1,314


Revenue 100,9 187,6 142,9 1,000,
87 36 12 382
Revenue 100,987 187,636 142,912 1,000,382
London Boarded 151 241 188 3,760
London Boarded 151 241 188 3,760
Transferred 4 18 11 227
Transferre
d 4 18 11 227 Deplaned 114 250 199 3,987

Deplaned 114 250 199 3,987 Revenue 106,753 198,744 159,478 3,189,554

Revenue 106,753 198,744 159,478 Paris


3,189,554 Boarded 146 182 161 2,089

Paris Boarded 146 182 161 2,089 Transferred 7 29 16 204

Transferre Deplaned 153 227 183 2,378


d 7 29 16 204
Revenue 123,456
SAS Techies 2009 195,468
11/02/21 151,477 1,969,201 14
Deplaned
ods listing close;
ods html path='c:\data' body='laguard.html'; title1 'Laguardia Flights by
Destination';
Laguardia Flights by Destination title2 'and Revenue, March 4-10';

and Revenue, March 4-10 proc format;


value $desname
  Min Max Mean Sum 'CPH'='Copenhagen'
'FRA'='Frankfurt'
Destinatio   'LON'='London'
n 'PAR'='Paris';
value $desback
Copenhag Boarded 81 154 131 786 'CPH'='cxBBDDCC‘
en 'FRA'='cxAACCBB'
Transferr 'LON'='cx99BBAA‘
ed 5 21 13 75 'PAR'='cx88AA99';

Deplaned 103 177 147 881 value deplback


low-105='lipk'
Revenue 109,8 196,5 139,9 839,70 245-250='vpapb'
85 40 51 5 other='ywh';
run;
Frankfurt Boarded 129 210 170 1,190
proc tabulate data=flights.laguardia format=comma9.
Transferr style={background=ywh}; class dest / style={background=cxCCEEDD
font_style=italic};
ed 5 22 13 91 classlev dest / style={background=$desback.};
var boarded transferred deplaned / style={background=cxCCEEDD};
Deplaned 147 237 188 1,314 var revenue / style=<parent>{foreground=black};
table dest*(boarded transferred deplaned*{style={background=deplback.}}
Revenue 100,9 187,6 142,9 1,000,3 revenue*{style=<parent>}),min max mean sum /
box={style={background=cxCCEEDD}};
87 36 12 82 keyword min max mean sum / style={background=cxCCEEDD
font_style=italic}; label dest='Destination';
London Boarded 151 241 188 3,760 format dest $desname.;
run;
Transferr ods html close;
ed 4 18 11 227 ods listing;

Deplaned 114 250 199 3,987

Revenue 106,7 198,7 159,4 3,189,5


53 44 78 54 SAS Techies 2009 11/02/21 15
Laguardia Flights by
Destination
keyword min max mean sum /
style={background=cxCCEEDD};
and Revenue,
  March 4-10
Min Max Mean Sum
Destination  
  Min Max Mean Sum

Destination  
Copenhagen Boarded 81 154 131 786
Copenhage Boarded 81 154 131 786
Transferre
n
d 5 21 13 75 Transferre
d 5 21 13 75
Deplaned 103 177 147 881
Deplaned 103 177 147 881
Revenue 109,885 196,540 139,951 839,705
Revenue 109,88 196,54 139,95
Frankfurt Boarded 129 210 170 1,190 5 0 1 839,705
Transferre Frankfurt Boarded 129 210 170 1,190
d 5 22 13 91
Transferre
Deplaned 147 237 188 1,314 d 5 22 13 91
Revenue 100,987 187,636 142,912 1,000,382 Deplaned 147 237 188 1,314
London Boarded 151 241 188 3,760 Revenue 100,98 187,63 142,91 1,000,38
7 6 2 2
Transferre
d 4 18 11 London
227 Boarded 151 241 188 3,760

Deplaned 114 250 199 3,987 Transferre


d 4 18 11 227
Revenue 106,753 198,744 159,478 3,189,554
Deplaned 114 250 199 3,987
Paris Boarded 146 182 161 2,089
Revenue 106,75 198,74 159,47 3,189,55
Transferre 3 4 8 4
d 7 29 16 204
Paris Boarded 146
SAS Techies 2009 182
11/02/21 161 2,089 16
Deplaned
Laguardia Flights by
Destination / box={style={background=cxCCEED
and Revenue,
  March 4-10
Min Max Mean Sum
[BOX cell]  Min Max Mean Sum
Destination  
Destinatio  
Copenhagen Boarded 81 154 131 786 n
Transferre Copenhag Boarded 81 154 131 786
d 5 21 13 75 en
Transferr
Deplaned 103 177 147 881 ed 5 21 13 75

Revenue 109,885 196,540 139,951 839,705 Deplaned 103 177 147 881

Frankfurt Boarded 129 210 170 1,190 Revenue 109,88 196,54 139,95
5 0 1 839,705
Transferre
d 5 22 13 91 Frankfurt Boarded 129 210 170 1,190

Deplaned 147 237 188 1,314 Transferr


ed 5 22 13 91
Revenue 100,987 187,636 142,912 1,000,382
Deplaned 147 237 188 1,314
London Boarded 151 241 188 3,760
Revenue 100,98 187,63 142,91 1,000,38
Transferre 7 6 2 2
d 4 18 11 227
London Boarded 151 241 188 3,760
Deplaned 114 250 199 3,987
Transferr
Revenue 106,753 198,744 159,478 3,189,554 ed 4 18 11 227

Paris Boarded 146 182 161 2,089 Deplaned 114 250 199 3,987

Transferre Revenue 106,75 198,74 159,47 3,189,55


3 4 8 4
d 7 29 16 204
SAS Techies 2009 11/02/21 17
Paris Boarded 146 182 161 2,089
Deplaned
Laguardia Flights by class dest / style={background=cxCCEEDD};
Destination
classlev dest / style={background=cxAACCBB};
and Revenue,
  March 4-10
Min Max Mean Sum
  Min Max Mean Sum
Destination  
Destination  
Copenhagen Boarded 81 154 131 786
Copenhage Boarded 81 154 131 786
Transferre n
Transferre
d 5 21 13 75
d 5 21 13 75
Deplaned 103 177 147 881
Deplaned 103 177 147 881
Revenue 109,885 196,540 139,951 839,705
109,88 196,54 139,95
Revenue
Frankfurt Boarded 129 210 170 1,190 5 0 1 839,705

Transferre Frankfurt Boarded 129 210 170 1,190


d 5 22 13 91 Transferre
Deplaned 147 237 188 1,314
d 5 22 13 91

Revenue 100,987 187,636 142,912 1,000,382


Deplaned 147 237 188 1,314

Revenue 100,98 187,63 142,91 1,000,38


London Boarded 151 241 188 3,760 7 6 2 2
Transferre London Boarded 151 241 188 3,760
d 4 18 11 227
Transferre
Deplaned 114 250 199 3,987 d 4 18 11 227
Revenue 106,753 198,744 159,478 3,189,554 Deplaned 114 250 199 3,987
Paris Boarded 146 182 161 2,089 Revenue 106,75 198,74 159,47 3,189,55
3 4 8 4
Transferre
d 7 29 16 Paris204 Boarded 146 182 161 2,089
SAS Techies 2009 11/02/21 18
Deplaned
ods listing close; ods html path='c:\data' body='laguard.html'; title1
'Laguardia Flights by Destination'; title2 'and Revenue, March 4-10';
Laguardia Flights by Destination proc format;
value $desname
and Revenue, March 4-10 'CPH'='<DIV>Copenhagen<P><IMG src="denmark.gif"></DIV>'
Mea 'FRA'='<DIV>Frankfurt<P><IMG src="germany.gif"></DIV>'
'LON'='<DIV>London<P><IMG src="uk.gif"></DIV>'
  Min Max n Sum 'PAR'='<DIV>Paris<P><IMG src="france.gif"></DIV>';
value $desback
Destination   'CPH'='cxBBDDCC'
'FRA'='cxAACCBB'
Boarded 81 154 131 786 'LON'='cx99BBAA'
Copenhagen 'PAR'='cx88AA99';
Transferr value deplback
ed 5 21 13 75 low-105='lipk'
245-250='vpapb'

          Deplaned 103


109,8
8
177
196,5
4
147
139,9
5
881 other='ywh';
value deplflyo
low-105='LOW traffic. Cut flights?'
245-250='HIGH traffic. Add flights?'
      Revenue 5 0 1 839,705 other=' ';
run;
Boarded 129 210 170 1,190
Frankfurt proc tabulate data=flights.laguardia format=comma9.
Transferr style={background=ywh}; class dest / style={background=cxCCEEDD
font_style=italic}; classlev dest / style={background=$desback.};
ed 5 22 13 91 var boarded transferred deplaned / style={background=cxCCEEDD};

         
var revenue / style=<parent>{foreground=black};
Deplaned 147 237 188 1,314
table dest*(boarded transferred deplaned*{style={background=deplback.
flyover=deplflyo.}} revenue*{style=<parent>}),min max mean sum /
100,9 187,6 142,9 1,000,3 box={style={background=cxCCEEDD}};
8 3 1 8 keyword min max mean sum / style={background=cxCCEEDD
      Revenue 7 6 2 2 font_style=italic};
label dest='Destination'; format dest $desname.; run;
Boarded 151 241 188 3,760 ods html close;
London ods listing;
Transferr
ed 4 18 11 227

          Deplaned 114


106,7
250
198,7
199
159,4
3,987
3,189,5
SAS Techies 2009 11/02/21 19
To create a drill-down graph, you
write a SAS program to do the
following:

◦ Create the initial chart that you want to


use, using SAS/GRAPH software. This
chart will become the primary chart in
your linked series of graphs.

◦ Create a variable to hold HREF


addresses for the linked HTML files.

◦ Define values for the new variable.

◦ Set ODS output to HTML.

◦ Attach links to the primary chart.

◦ Create the secondary, linked charts and


tables.

SAS Techies 2009 11/02/21 20


data work.saletrnd;
set finance.prdsal2;

/* create variables to hold HREF address strings */

length PriDrill $ 40 SecDrill $ 40;

/* define the HTML links for the primary chart */

if year=1995 then pridrill='HREF="sales95.html"';


if year=1996 then pridrill='HREF="sales96.html"';

if quarter=1 then secdrill='HREF="#salesq1"';


if quarter=2 then secdrill='HREF="#salesq2"';
if quarter=3 then secdrill='HREF="#salesq3"';
if quarter=4 then secdrill='HREF="#salesq4"';

SAS Techies 2009 11/02/21 21


/* title of the primary chart */

format actual dollar10.0; title 'Total Sales by Year';


run; /* create a bar chart of sales by year... */
/* assign the HTML links held by PriDrill
*/
ods listing close;
proc gchart data=work.saletrnd;
ods html vbar year / subgroup=prodtype
discrete
path='c:\data\sales\reports sumvar=actual html=pridrill;
' run;
body='totalsales.html'; /* specify the HTML file name of the
secondary chart... */
/* set the title and create a bar chart
goptions device=gif where YEAR=1995 */
xpixels=480 ypixels=360; ods html body='sales95.html';
title 'Sales for 1995 by Quarter';

SAS Techies 2009 11/02/21 22


proc gchart data=work.saletrnd;
vbar quarter / sumvar=actual
subgroup=product discrete
proc gchart data=work.saletrnd;
html=secdrill;
vbar quarter / sumvar=actual
subgroup=product discrete where year=1995;
html=secdrill; run;
where year=1995;
run; /* specify the HTML file name of the
secondary chart... */
/* set the title and create a bar chart
/* specify the HTML file name of the where YEAR=1996 */
secondary chart... */
/* set the title and create a bar chart
where YEAR=1996 */ ods html body='sales96.html';
title 'Sales for 1996 by Quarter';
ods html body='sales96.html'; proc gchart data=work.saletrnd;
title 'Sales for 1996 by Quarter'; vbar quarter / sumvar=actual
subgroup=product discrete
proc gchart data=work.saletrnd;
html=secdrill;
vbar quarter / sumvar=actual
subgroup=product discrete where year=1996;
html=secdrill; run;
where year=1996; quit;
run; ods html close;
ods listing;
quit;

SAS Techies 2009 11/02/21 23


/* create a named anchor in the ods html anchor='salesq2';
current HTML page...set a */ title '2nd Quarter 1998 Sales by
/* title and create a table where Country';
YEAR=1995 & QUARTER=1-4 */
proc tabulate data=work.saletrnd
ods html anchor='salesq1'; format=dollar10.0;
title '1st Quarter 1995 Sales by class country product;
Country';
var actual;
table (country all)*(product all),
proc tabulate data=work.saletrnd sum*actual;
format=dollar10.0; where year=1998 and quarter=2;
class country product; run;
var actual;
table (country all)*(product all), ods html close;
sum*actual;
where year=1995 and quarter=1; ods listing;
run;

ods html close;


ods listing;

SAS Techies 2009 11/02/21 24

You might also like