ods markup and tagsets: a tutorial

90
Copyright © 2004, SAS Institute Inc. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or Trademarks of their respective companies ODS Markup and Tagsets, A tutorial. Eric Gebhart

Upload: simienc

Post on 03-Nov-2014

19 views

Category:

Technology


1 download

DESCRIPTION

This presentation by Eric Gebhart is an excellent tutorial on SAS ODS markup and tagsets which can be used for arranging SAS reporting output in most any format. Great for creating dashboards too!

TRANSCRIPT

Page 1: Ods Markup And Tagsets: A Tutorial

Copyright © 2004, SAS Institute Inc. All rights reserved.SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or Trademarks of their respective companies

ODS Markup and Tagsets,A tutorial.Eric Gebhart

Page 2: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 2

Page 3: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 3

ODS MARKUP!

Page 4: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 4

ODS Markup & Tagsets

Page 5: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 5

Page 6: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 6

Proc Template.

It is NOT what you think it is!

Page 7: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 7

Tagsets are ODS Destinations

ODS Markup tagset=HTML4 ....

ODS Tagsets.HTML4 ....

ODS HTML4 ....

ODS HTML ....

Page 8: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 8

ODS HTML is ODS Markup!

Page 9: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 9

ods tagsets.short_map file = "body.xml" frame = "frame.xml" contents = "contents.xml" pages = "pages.xml" code = "code.xml" data = "data.xml" stylesheet = "stylesheet.xml";ods _all_ close;

The ODS Markup Statement

Page 10: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 10

Special, Named Destinations.

● HTML, PHTML, HTMLCSS, HTML4, CHTML● CSV, CSVByline, CSVAll● LaTeX, Troff● XML, SASReport, DocBook● IMode

Page 11: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 11

What is Different ?

One more output file.

Stylesheet Behavior.

More Options.

Page 12: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 12

The same options as before.

Ods html file='test.html' (headtext='<meta text=”my headtext”>', metatext='text=”my meta text”, url='http://www.sas.com/test.html' ) newfile=table;

Page 13: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 13

Multiple Stylesheet URL's!

ODS html file = ”test.html” stylesheet = ”test.css” (url=”test.css corp.css corpnav.css”);

Page 14: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 14

Multiple Personality Disorder.

Ods tagsets.myhtml file=”test.html” Alias=”NoNotes”;

Page 15: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 15

Make up your own Options!

ODS tagsets.test file=”test.txt” options(embedded_titles = 'yes' Orientation = 'landscape' Doc = 'Help');

Page 16: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 16

Options inside the tagset.

define tagset tagsets.test;

define event initialize; putvars $options _name_ ': ' _value_ nl; end; end;

Page 17: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 17

The tagset Output.

EMBEDDED_TITLES: yesORIENTATION: landscapeDOC: Help

Page 18: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 18

One more method of control!

ODS tagsets.htmlpanel file = ”test.html”;

ODS tagsets.htmlpanel event = panel(start);......ODS tagsets.htmlpanel event = panel(finish);

ODS tagsets.htmlpanel close;

Page 19: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 19

ODS Markup is like ODS HTML,

PLUS!

Page 20: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 20

Getting a listProc template;list tagsets;

Listing of: SASHELP.TMPLMST Path Filter is: Tagsets Sort by: PATH/ASCENDING

Obs Path Type 1 Tagsets Dir 2 Tagsets.Chtml Tagset 3 Tagsets.Colorlatex Tagset 4 Tagsets.Csv Tagset

Page 21: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 21

The HTML Family

●Phtml●HtmlCss●Html4●Chtml●Imode (chtml)

Page 22: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 22

PHTML, Plain HTML.

Simple 12 element Stylesheet

No class attributes.

No Fancy features.

Page 23: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 23

HTMLCSS.

Full Stylesheet

Fancy Features

Page 24: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 24

HTML4 is ODS HTML

Same as HtmlCSS

More like Previous Releases

Page 25: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 25

CHTML - Compact HTML.

iSNo

Subset of HTML.

No Styles.

Super Set of Imode.

Page 26: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 26

Data Transport and Excel.CSV, CSVByline, CSVAll

PYX

MSOffice2K

ExcelXP

DDE

http://support.sas.com/news/feature/04jul/excelsupport.html

Page 27: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 27

CSV

"Obs","Name","Sex","Age","Height","Weight""1","Alfred","M",14,69.0,112.5"2","Alice","F",13,56.5,84.0"3","Barbara","F",13,65.3,98.0

Page 28: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 28

PYX

(data-AlfredAtype "string"Ajust "l"Acolcount "1"Acol "2"Asection "body"Aclass "Data")data

Page 29: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 29

The ExcelXP Tagset!

Page 30: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 30

Publications, Papers, PDF.

LaTeX

Troff

DocBook

Page 31: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 31

LaTeX Tagsets

LaTeX

SimpleLaTeX

TablesOnlyLaTeX

Page 32: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 32

Combined Slide Bars - PDF via LaTeX

Page 33: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 33

Other Miscellaneous Tagsets.

ODSStyle

Style_Popup

Style_Display

NamedHTML

MVSHTML

Page 34: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 34

Page 35: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 35

Tagsets are Collections of Events

Page 36: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 36

Events Define Actions & Output.

define event doc; start: put HTMLDOCTYPE nl; put “<html>” nl; finish: put "</html>" nl; end;

Page 37: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 37

A very simple tagset.proc template; define tagset tagsets.plain;

define event data; put “Data: “ value nl; end;

define event header; put “Header: “ value nl; end;

end;run;

Page 38: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 38

Header: ObsHeader: NameHeader: SexHeader: AgeHeader: HeightHeader: WeightHeader: 1Data: AlfredData: MData: 14Data: 69.0Data: 112.5

ods tagsets.plain file="plain.txt";proc print data=sashelp.class;run;ods tagsets.plain close;

Page 39: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 39

Label, Value Pairs

Becomes this:

<Table background="grey" foreground="blue" cellpadding="5">

Putq '<Table' ' background=' background;putq 'foreground=' foreground;putq 'cellpadding=' cellpadding;put '>' nl;

With no attribute values, it becomes:

<Table>

Page 40: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 40

If Statements.

Put 'Foreground is blue!' nl /if cmp('blue', foreground);

Put 'Foreground is not red!' nl /if ^cmp('red', foreground);

Page 41: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 41

AND and OR, sort of...

Put 'Some variables have a value.' nl /if any(background, foreground, cellpadding, value);

Put 'All variables have a value.'' nl /if exists(background, foreground, cellpadding, value);

Page 42: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 42

Contains a Substring.

Set $myvar “this is random text”;

put “myvar has ran” nl /if contains($myvar, “ran”);

Page 43: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 43

Simple if test, Where clauses.

Set $myvar “this is random text”;Set $mytest “True”;

put “myvar has length” nl /if $myvar;

put “longer than 10” nl /if length($myvar) > 10

break /if $mytest;

Page 44: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 44

Break, Breakif

Break /if ^$options; Trigger alternate_event /if $do_something_else;Break /if $do_something_else; Trigger alternate_event /breakif $do_something_else;

Page 45: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 45

A list of images.proc template; define tagset tagsets.gifs;

define event branch; put label " "; end;

define event image; put url nl; end; end; run;

Page 46: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 46

The Output

Name=Alfred temp/gplot.gifName=Alice temp/gplot1.gifName=Barbara temp/gplot2.gif

Page 47: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 47

A Prettier Report.proc template; define tagset tagsets.gifs2;

define event branch; set $name scan(label, 2, '='); end;

define event image; put url " " $name nl; end; end; run;

Page 48: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 48

Nicer looking Output

temp/gplot.gif Alfredtemp/gplot1.gif Alicetemp/gplot2.gif Barbara

Page 49: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 49

The Set Statement.

set $myvar “foreground is” forground;

Always creates a string.

Variables always start with $.

Page 50: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 50

The Eval Statement.

Eval $count 0;

Eval $count $count + 1;

set $myvar “this is a test”;

Eval $index index($myvar, 'test');

Page 51: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 51

Data Step Functions.

Can be used anywhere.

Cannot be nested except in where clauses.

Page 52: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 52

Simple Needs, Simple Tagsets.

Page 53: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 53

SQL ???

Create table CLASS (Name varchar(7), Sex varchar(1), Age float, Height float, Weight float);

Insert into CLASS(Name, Sex, Age, Height, Weight) Values ('Alfred', 'M', 14, 69.0, 112.5); ... ...

Page 54: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 54

Dictionaries

define event type_translations; set $types['string'] 'varchar'; set $types['double'] 'float'; set $types['int'] 'integer'; end;

/* column name translation */ define event name_translations; set $name_trans['desc'] 'description'; end;

Page 55: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 55

The Initialize Event

define event initialize; trigger type_translations; trigger name_translations;

/* types that need widths */ set $types_with_widths['string'] "True";

/* types that need quotes */ set $types_with_quotes['string'] "True"; end;

Page 56: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 56

Creating Listsdefine event colspec_entry;

set $lowname lowcase(name);

do /if $name_trans[$lowname]; set $names[] $name_trans[$lowname]; else; set $names[] $lowname; done;

Page 57: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 57

define event table_body; put "Create table " $table_name "("; eval $i 1; unset $not_first; do /while $i <= $names; /* comma's only after the first name */ put ', ' /if $not_first; put $names[$i] " "; put $columns[$i]; eval $i $i+1; set $not_first "True"; done; put ");" nl; end;

Page 58: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 58

iterate $types do /while _name_; put _name_ “: “ _value_ nl; next $types; done;

Looping through A Dictionary

Page 59: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 59

XBRL, Data Interchange

Page 60: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 60

Better Stripes.

Page 61: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 61

Counting Rows

Page 62: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 62

Streams.

Designated by $$

Can hold large amounts of data

Not limited by memory

Can be opened, closed and flushed.

Page 63: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 63

Streams by example

open junk;put “This goes to junk.” nl;put “ More stuff.” nl;close;

open trash;put $$junk 'This goes to trash.';putstream junk; put “ This goes to trash too.”;

open junk;put “ Even more stuff”;close;

set $$junk “A completely new junk.”;set $$junk $$junk “ Appending to the end”;

unset $$junk

Page 64: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 64

Byline Modification

Page 65: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 65

Repeating Row Headers

Page 66: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 66

Simple Needs, Simple Tagsets.

Page 67: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 67

Slide Bars.

Page 68: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 68

Craeting Slide Bars.

proc print data=sashelp.class; var name; var sex; var age; var height / style(data) = slider[just=center tagattr="slider-80"]; var weight / style(data) = slider[just=center tagattr="slider-150"];run;

Page 69: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 69

WebSite Integration

Page 70: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 70

Sashelp.class, My Favorite.

Page 71: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 71

Page 72: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 72

Page 73: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 73

Page 74: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 74

Tagset Inheritance. Define tagset tagsets.SSV;

parent = tagsets.csv; define event header; start: put ';' / if ^cmp(COLSTART, "1"); put '"'; put VALUE; finish: put '"'; end;.....

Page 75: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 75

Tagset Attributes

Define tagset tagsets.mytags; map = '<>&'; mapsub = '/&lt;/&gt;/&amp;/'; nobreakspace = '&nbsp;' ; embedded_stylesheet = yes; output_type = html; lognote = “you are using my special tagset”;

Page 76: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 76

Using Options

define event options_set; trigger setup_options;end;

define event setup_options; trigger nls_numbers; trigger options_setup; trigger documentation; end;

ODS tagsets.excelxp options(embedded_titles='yes');

Page 77: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 77

Mvar embedded_titles;define event options_setup; set $options['test'] "test" /if ^$options; do /if $options['EMBEDDED_TITLES']; do /if cmp($options['EMBEDDED_TITLES'], "yes"); set $embedded_titles "true" ; else; unset $embedded_titles; done; else; do /if cmp(embedded_titles, "yes"); set $embedded_titles "true" ; else; unset $embedded_titles; done; done;

Page 78: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 78

Creating Help and documentation.

define event documentation; break /if ^$options; trigger quick_reference /if cmp($options['DOC'], 'quick'); trigger help /if cmp($options['DOC'], 'help'); end;

define event help; putlog "============================== “; putlog “The EXCELXP Tagset Help Text."; ... trigger quick_reference; end;

Page 79: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 79

Extended Procedural Controls.

Eval $count 10;do /while $count < 10; eval $count $count+1; stop /if $count = 9; continue /if $count = 3; put $count nl;else; put “Count was already > 10” nl;done;

Page 80: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 80

Else If

do /if $count < 10; put “count is < 10”; nl;else /if $count = 11; put “Count is11” nl;else /if $count = 12; put “Count is 12” nl;else; put “Count is > 12” nl;done;

Page 81: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 81

A process for Tagset Creation

● Define the goal● Identify an Event● Locate the Event Code● Explore the available variables.

Page 82: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 82

Identify and Locate.

Search the Output to be modified.Search the Tagset for the corresponding Event

Search the Output of the Event_Map Tagset.

Look for convienent events with short_map.

Page 83: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 83

Finding & Exploring with Event Map.

ods tagsets.event_map file="map.xml";

<image event_name="image" trigger_name="attr_out" output_name="Gplot" output_label="Plot of Weight * Height" index="IDX" just="c" url="gplot.gif" />

Page 84: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 84

Exploring Variables with Putvars.

Put “Event variables” nl;Putvars Event _name_ ': ' _value_ nl;

Put “Style variables” nl;Putvars Style _name_ ': ' _value_ nl;

Put “Options” nl;Putvars $Options _name_ ': ' _value_ nl;

Page 85: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 85

Finding Other Useful Events.

Default_Event = putall;

Define event putall; put '<' Event_name nl; Putvars Event _name_ ': ' _value_ nl; Putvars Style _name_ ': ' _value_ nl; Putvars Mem _name_ ': ' _value_ nl; put '>' Event_name nl;End;

Page 86: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 86

Using a PutLog event.

Define event putlog; putlog “Event:” event_name nl; Putlog “Name is” “:” name; Putlog “Count is” “:” $count;end;

Page 87: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 87

Locating Alfred

<branch event_name="branch" trigger_name="attr_out" class="ByContentFolder" value="Name=Alfred" name="ByGroup1" label="Name=Alfred" index="IDX" just="c" url="junk.xml#IDX" hreftarget="body">

Page 88: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 88

A Solution.proc template; define tagset tagsets.gifs2;

define event branch; set $name scan(label, 2, '='); end;

define event image; put url " " $name nl; end; end;run;

Page 89: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 89

Page 90: Ods Markup And Tagsets: A Tutorial

Copyright © 2003, SAS Institute Inc. All rights reserved. 90

Useful Links

ODS Markup, New Tagsets, Howto's.

http://support.sas.com/rnd/base/topics/odsmarkup/

Introduction to Tagsets.

http://support.sas.com/rnd/base/topics/odsmarkup/tagsets.html

The Template FAQ.

http://support.sas.com/rnd/base/topics/templateFAQ/Template.html

[email protected]

[email protected]