Вы находитесь на странице: 1из 24

SASTechies

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

◦ SAS Tables,
◦ Listings,
◦ Basic Statistics Procedures with
SAS
◦ Graphs TLG’s

◦ ODS HTML
◦ Proc Report and Other Utility
Procedures

SAS Techies 2009 11/13/09 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/13/09 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/13/09 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/13/09 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/13/09 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
◦ FRAME=file-specification HTML output.

 identifies the file that integrates the table ◦ CONTENTS=file-specification


of contents, the page contents, and the  identifies a table of contents that links
body file. If you specify FRAME=, you to the body file.
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/13/09 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/13/09 8


URL= suboption in a file
specification: HTML-file- ◦ Uniform-Resource-Locator
specification(URL=' Uniform- provides a URL for HTML-file-
Resource-Locator') where specification. ODS uses this
URL instead of the file name in
◦ HTML-file-specification opens all the links and references that
the HTML destination and it creates that point to the file.
specifies the file to write to.
Use the URL= suboption in any ◦ URL= is useful for building
ODS file specification except HTML files that may be moved
FRAME= (because no ODS file from one location to another. If
references the frame file). 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/13/09 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/13/09 10


you want to display these  Absolute URLs Alternately, in
this ODS HTML statement, the
files from a Web server. URL= 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/da
ta.html’)
contents='c:\records\toc.html'
(url='http://mysite.com/mycontents/t
oc.html') frame='c:\records\frame.html';

SAS Techies 2009 11/13/09 11


Obs ID Name Sex Age Date Heigh Weigh ActLev Fee ◦ STYLE=style-name where style-name
t t el is the name of a valid SAS or user-
defined style definition.
12458 Murray, W M 27 1 72 168HIGH 85.20 ◦ Don't enclose style-name in quotation
marks.
22462 Almers, C F 34 3 66 152HIGH 124.80
ods listing close;
ods html
32501 Bonaventure F 31 17 61 123LOW 149.75
,T body='c:\records\data.html'(url='data.html')
contents='c:\records\toc.html'(url='toc.html‘)
42523 Johnson, R F 43 31 63 137MOD 149.75 frame='c:\records\frame.html'
style=beige;
52539 LaMance, K M 51 4 71 158LOW 124.80 proc print data=clinic.admit label; var id sex
age height weight actlevel; label
actlevel='Activity Level'; run;
62544 Jones, M M 29 6 76 193HIGH 124.80
proc print data=clinic.stress2; var id resthr
maxhr rechr; run;
72552 Reberson, P F 32 9 67 151MOD 149.75 ods html close; ods listing;

82555 King, E M 35 13 70 173MOD 149.75

92563 Pitts, D M 34 22 73 154LOW 124.80

102568 Eberhardt, S F 49 27 64 172LOW 124.80

SAS Techies 2009 11/13/09 12


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

SAS Techies 2009 11/13/09 13


Laguardia Flights by Destination
/ style={background=lib} 
and Revenue, March 4-10 font_style=italic} ;
  Min Max Mean Sum   Min Max Mean Sum
Destination   81 154 131 786
Destination   81 154 131 786

Copenhagen Boarded Copenhagen Boarded


Transferred 5 21 13 75 Transferred 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
Transferred 5 22 13 91
Deplaned 147 237 188 1,314

Deplaned 147 237 188 1,314 Revenue 100,98 187,63 142,91 1,000,38
7 6 2 2
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
Transferred 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 Paris 


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

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

Transferred 7 29 16 204 Deplaned 153 227 183 2,378

Revenue 123,456 195,468 151,477 1,969,201


SAS Techies 2009 11/13/09 14
Deplaned 153 227 183 2,378
ods listing close;
ods html path='c:\data' body='laguard.html'; title1 'Laguardia Flights by
Laguardia Flights by Destination Destination';
title2 'and Revenue, March 4-10';

and Revenue, March 4-10 proc format;


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

Deplaned 103 177 147 881 value deplback


low-105='lipk'
Revenue 109,885 196,540 139,951 839,705 245-250='vpapb'
other='ywh';
run;
Frankfurt  Boarded 129 210 170 1,190
proc tabulate data=flights.laguardia format=comma9.
5 22 13 91 style={background=ywh}; class dest / style={background=cxCCEEDD
Transferred font_style=italic};
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,987 187,636 142,912 1,000,382 revenue*{style=<parent>}),min max mean sum /
box={style={background=cxCCEEDD}};
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;
Transferred 4 18 11 227
ods html close;
ods listing;

Deplaned 114 250 199 3,987

Revenue 106,753 198,744 159,478 3,189,554


SAS Techies 2009 11/13/09 15
Laguardia Flights by Destination
keyword min max mean sum / 
and Revenue, March 4-10 style={background=cxCCEEDD};
  Min Max Mean Sum
Min Max Mean Sum
Destination   81 154 131 786
Destination   81 154 131 786
Copenhagen Boarded
5 21 13
Copenhagen
75
Boarded
Transferred
Transferred 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

Transferred 5 22 13Frankfurt 
91 Boarded 129 210 170 1,190

Transferred 5 22 13 91
Deplaned 147 237 188 1,314

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,987 187,636 142,912 1,000,382

Transferred 4 18 11 227
London  Boarded 151 241 188 3,760

Deplaned 114 250 199 3,987 Transferred 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,753 198,744 159,478 3,189,554
Transferred 7 29 16 204

Paris  Boarded 146 182 161 2,089


SAS Techies 2009 11/13/09 16
Deplaned 153 227 183 2,378
Laguardia Flights by Destination
/ box={style={background=cxCCEED
and Revenue,
  March 4-10
Min Max Mean Sum
[BOX cell]  Min Max Mean Sum
Destination   81 154 131 786
Destination   81 154 131 786
Copenhagen Boarded
Transferred 5 21 13 75 Copenhagen Boarded
Transferred 5 21 13 75
Deplaned 103 177 147 881

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

Frankfurt  Boarded 129 210 170 1,190 Revenue 109,885 196,540 139,951 839,705

Transferred 5 22 13 91
Frankfurt  Boarded 129 210 170 1,190

147 237 188 1,314 Transferred 5 22 13 91


Deplaned
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,987 187,636 142,912 1,000,382
Transferred 4 18 11 227

London  Boarded 151 241 188 3,760


Deplaned 114 250 199 3,987
Transferred 4 18 11 227
Revenue 106,753 198,744 159,478 3,189,554

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

Transferred 7 29 16 204 Revenue 106,753 198,744 159,478 3,189,554

146 182 161 2,089


2,378 Paris 
SASBoarded
Techies 2009 11/13/09 17
Deplaned 153 227 183
Laguardia Flights by Destination
class dest / style={background=cxCCEEDD};
and Revenue, March 4-10
classlev dest / style={background=cxAACCBB};
  Min Max Mean Sum
  Min Max Mean Sum
Destination   81 154 131 786
Destination   81 154 131 786
Copenhagen Boarded
Copenhagen Boarded
Transferred 5 21 13 75
Transferred 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

5 22 13Frankfurt 
91 Boarded 129 210 170 1,190
Transferred
Transferred 5 22 13 91

Deplaned 147 237 188 1,314

100,987 187,636 142,912 1,000,382 Deplaned 147 237 188 1,314


Revenue
151 241 188 3,760 Revenue 100,987 187,636 142,912 1,000,382
London  Boarded
Transferred 4 18 11 227
London  Boarded 151 241 188 3,760

Transferred 4 18 11 227
Deplaned 114 250 199 3,987

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,753 198,744 159,478 3,189,554
Transferred 7 29 16 204
Paris  Boarded 146 182 161 2,089
SAS Techies 2009 11/13/09 18
Deplaned 153 227 183 2,378 Transferred 7 29 16 204
ods listing close; ods html path='c:\data' body='laguard.html'; title1
Laguardia Flights by 'Laguardia Flights by Destination'; title2 'and Revenue, March 4-10';
proc format;
Destination value $desname
'CPH'='<DIV>Copenhagen<P><IMG src="denmark.gif"></DIV>'
 and Revenue, March 4-10
Min Max Mean Sum 'FRA'='<DIV>Frankfurt<P><IMG src="germany.gif"></DIV>'
'LON'='<DIV>London<P><IMG src="uk.gif"></DIV>'
'PAR'='<DIV>Paris<P><IMG src="france.gif"></DIV>';
value $desback
Destination 81 154 131 786 'CPH'='cxBBDDCC'
'FRA'='cxAACCBB'
Copenhagen Boarded 'LON'='cx99BBAA'
'PAR'='cx88AA99';
Transferred 5 21 13 75 value deplback
low-105='lipk'
245-250='vpapb'
Deplaned 103 177 147 881 other='ywh';
value deplflyo
Revenue 109,885 196,540 139,951 839,705 low-105='LOW traffic. Cut flights?'
245-250='HIGH traffic. Add flights?'
other=' ';
run;
Frankfurt Boarded 129 210 170 1,190
proc tabulate data=flights.laguardia format=comma9.
Transferred 5 22 13 91 style={background=ywh}; class dest /
style={background=cxCCEEDD font_style=italic}; 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
100,987 187,636 142,912 1,000,382 deplaned*{style={background=deplback. flyover=deplflyo.}}
Revenue revenue*{style=<parent>}),min max mean sum /
box={style={background=cxCCEEDD}};
keyword min max mean sum / style={background=cxCCEEDD
font_style=italic};
London Boarded 151 241 188 3,760 label dest='Destination'; format dest $desname.; run;
ods html close;
Transferred 4 18 11 227 ods listing;

Deplaned 114 250 199 3,987

106,753 198,744 159,478 3,189,554 SAS Techies 2009 11/13/09 19


Revenue
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/13/09 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/13/09 21


/* title of the primary chart */

title 'Total Sales by Year';


format actual dollar10.0;
run; /* create a bar chart of sales by
year... */
/* assign the HTML links held by
PriDrill */
ods listing close;
ods html proc gchart data=work.saletrnd;
vbar year / subgroup=prodtype
path='c:\data\sales\reports' discrete
sumvar=actual html=pridrill;
body='totalsales.html'; run;

/* specify the HTML file name of the


goptions device=gif secondary chart... */
xpixels=480 ypixels=360; /* set the title and create a bar chart
where YEAR=1995 */

ods html body='sales95.html';


title 'Sales for 1995 by Quarter';

SAS Techies 2009 11/13/09 22


proc gchart data=work.saletrnd;
vbar quarter / sumvar=actual
subgroup=product discrete
proc gchart data=work.saletrnd; html=secdrill;
vbar quarter / sumvar=actual where year=1995;
subgroup=product discrete run;
html=secdrill;
where year=1995; /* specify the HTML file name of the
run; 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 ods html body='sales96.html';
where YEAR=1996 */ title 'Sales for 1996 by Quarter';
proc gchart data=work.saletrnd;
ods html body='sales96.html'; vbar quarter / sumvar=actual
title 'Sales for 1996 by Quarter'; subgroup=product discrete
proc gchart data=work.saletrnd; html=secdrill;
vbar quarter / sumvar=actual where year=1996;
subgroup=product discrete run;
html=secdrill; quit;
where year=1996; ods html close;
run; ods listing;

quit;

SAS Techies 2009 11/13/09 23


/* create a named anchor in the current ods html anchor='salesq2';
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
Country'; class country product;
var actual;
proc tabulate data=work.saletrnd table (country all)*(product all),
format=dollar10.0; sum*actual;
class country product; where year=1998 and
var actual; quarter=2;
table (country all)*(product all), run;
sum*actual;
where year=1995 and quarter=1; ods html close;
run; ods listing;
ods html close;
ods listing;

SAS Techies 2009 11/13/09 24