Title: SAS
1- SAS ODS Technology for Todays Decision Makers
- Sunil Gupta
- Quintiles
2SAS Users
- Manager Excel file, HTML drill down files
3Agenda
- Whats Unique about ODS?
- Creating Excel Files
- Efficient Data Analysis with ODS
- Custom Formats in RTF files
- Applying Style Syntax in Proc Tabulate and Proc
Print
4Whats Unique about ODS?
- Destinations (Remember to turn off ODS)
- (Defines the output file type HTML, RTF, PDF,
LISTING, - OUTPUT)
- Creating Output Objects
- (Reference to Output Object Names)
- Creating Output Files with Style
- (Reference to SAS-Supplied Styles)
- Part of SAS/Base
5Defining Output Destinations
6Create Demog Data Set
- Patient, Sex, Height, Weight, Age, Race, Drug
- (n25 records)
7Creating Output Files Report Files
- ODS ltFile Typegt File
-
- SAS Procedure(s)
- ODS ltFile Typegt CLOSE
- Where File Type HTML, RTF, Listing, PDF, ..
- Keep consistent filename types .html, rtf, lst,
pdf, ..
Results of one or more SAS Procedures
8Example 1a. Create Excel File demog.xls
- lt ODS Statement with minimal stylegt
- PROC UNIVARIATE DATADEMOG
- VAR WEIGHT
- RUN
- lt ODS Statement gt
9Example 1a. Create Excel File
- ODS HTML FILE 'c\how\gupta\demog.xls
- STYLE minimal
- PROC UNIVARIATE DATADEMOG
- VAR WEIGHT
- RUN
- ODS HTML CLOSE
- Try this in the office - Undocumented Feature.
- See SAS paper on Excel and ODS. (HTML, .xls)
Excel
10Example 1a. Create Excel File demog.xls
Each result item is in its own cell!
11Example 1b. Create Demog_Style HTML File with
Style
- lt ODS HTML Statement with barrettsblue style gt
- PROC UNIVARIATE DATADEMOG
- VAR WEIGHT
- RUN
- lt ODS HTML Statement gt
12Example 1b. Create HTML File with Style
- ODS HTML FILE 'c\how\gupta\demog_style.html'
- STYLE barrettsblue
- PROC UNIVARIATE DATADEMOG
- VAR WEIGHT
- RUN
- ODS HTML CLOSE
13Example 1b. Create HTML File with Style
(BARRETTSBLUE)
14Creating Output Files with Style
- SAS Supplied Styles (partial list)
- NAME DESCRIPTION
- BarrettsBlue Blue header background, light table
background - Beige Beige header text, white text in
table - Brick Brick color header text, white
text in table - Brown Brown title, black header, light
table background -
- (see Quick Results with the Output Delivery
System book)
Proc Template list styles run
15Efficient Data Analysis with ODS
- Selecting Objects
-
- Creating Output Data sets
- Creating Multiple Data sets with the MATCH_ALL
option - Using Traffic Lighting conditions to identify
significance - Creating Plots and Tables as RTF file
-
16Example 2a. Create Output Data Set Measure from
Basic Measures Info
- ODS OUTPUT ltobject namegt ltdata set namegt
-
- PROC UNIVARIATE DATADEMOG
- VAR WEIGHT
- RUN
- ODS OUTPUT CLOSE
17Creating Output Objects
O U T P U T O B J E C T S
18Identifying Output Objects List File
ODS TRACE ON / LABEL LISTING (One of Several
Output Objects Created)
Name BasicMeasures Label
Basic Measures of Location and Variability Templat
e base.univariate.Measures Path
Univariate.weight.BasicMeasures Label Path
'The Univariate Procedure'.'weight'.'Basic
Measures of Location and
Variability'
Except for Proc Print, Proc Tabulate and Proc
Report.
19Example 2a. Create Output Data Set Measure from
Basic Measures Info
- ODS TRACE ON / LABEL LISTING
- ODS OUTPUT ltobject namegt ltdata set namegt
-
- PROC UNIVARIATE DATADEMOG
- VAR WEIGHT
- RUN
- ODS OUTPUT CLOSE
20Example 2a. Create Output Data Set Measure from
Basic Measures Info
- ODS OUTPUT BASICMEASURES MEASURE
-
- PROC UNIVARIATE DATADEMOG
- VAR WEIGHT
- RUN
- ODS OUTPUT CLOSE
- Proc print run
- Note OUTPUT OUT statement in procedures are
still valid!
(Data set Name)
(Object Name)
21Example 2a. Create Output Data Set Measure
- Proc print of MEASURE Output Data Set
- Measure as SAS Data set
- Var Loc
- Obs Name Measure LocValue VarMeasure
VarValue - 1 weight Mean 198.6800 Std Deviation
44.55682 - 2 weight Median 199.0000 Variance
1985 - 3 weight Mode . Range
159.00000 - 4 weight _ Interquartile Range
56.00000 - Get comfortable with the output data set.
22Creating Output Data Sets
- Works with any SAS Procedure
- All results are available in the data set
- Options are available for creating multiple data
sets - Note Requires having information about the
object. - Can use the ODS TRACE statement to get this
information.
23Example 2b. Create Multiple Data Sets with the
MATCH_ALL option
ODS OUTPUT BASICMEASURES / object
name / (MATCH_ALL MEASURE_DSN
/ macro name / PERSIST PROC)
/ maintain selection list /
MEASURE / data set names -
measure, measure1, measure2 / PROC UNIVARIATE
DATADEMOG VAR WEIGHT HEIGHT RUN PROC
UNIVARIATE DATADEMOG VAR AGE RUN ODS OUTPUT
CLOSE PUT Macro variable MEASURE_DSN
24Example 2b. Create Multiple Data Sets with the
MATCH_ALL option
data allmeans set measure_dsn / set
measure measure1 measure2 / where
locmeasure 'Mean' keep varname locmeasure
locvalue run Var
Loc Obs Name Measure LocValue
1 weight Mean 198.6800
2 height Mean 66.8400 3
age Mean 56.5280
25Example 3. Using Traffic Lighting low green,
high orange
proc format value traffic low - 99
100 - high quit ods html file
c\how\gupta\print_results.htm proc report
dataallmeans nowd columns varname locvalue
define varname/ Variable define locvalue /
Mean style background
ltformatgt run ods html close
26Example 3. Using Traffic Lighting low green,
high orange
proc format value traffic low - 99 green
/ cx006600 / 100 - high
orange / cxFF9900 / quit ods html file
c\how\gupta\print_results.htm proc report
dataallmeans nowd columns varname locvalue
define varname/ Variable define locvalue /
Mean style background
traffic. run ods html close
27Using Traffic Lighting Conditions to identify
significance
GreaterThan 100
Make results visually informative.
28Example 4. Create Plots and Tables as Plots.rtf
File
- lt ODS Statement to create rtf file gt
- proc univariate data demog lt plots gt
- var weight
- lt histogram / cfillcyangt
- run
- ods rtf close
29Example 4. Create Plots and Tables as Plots.rtf
File
- ods rtf file c\how\gupta\plots.rtf
- proc univariate data demog plots
- var weight
- histogram / cfillcyan
- run
- ods rtf close
Plots.rtf
You can have it all - tables and plots in one
file!
30Example 4. Creating Plots and Tables as RTF File
31Customize RTF File RTF Control Words
- Effect Control Word
- Italics \i
- underline \ul
- bullet \bullet
- bold \b
- subscript \sub
- superscript \super
- strike \strike
- (http//msdn.microsoft.com/library/default.asp?url
/library/en - -us/dnrtfspec/html/rtfspec.asp)
32Customize RTF File RTF Control Words
- 1. Carrot symbol is best as the escapechar
symbol since the RTF syntax uses the \ symbol. - 2. Use the following formula and conditions
- text R\rtf-control-word text
\rtf-control-word0 - a. Double quotes ( ) around text strings.
- b. Concatenate all strings with operator.
- c. Use single quote (to set R) and then
double quote to start rtf-control-word string
(\rtf-control-word). - d. The text to be affected.
- e. Repeat and close each rtf-control-word
string with 0, double quote () then single quote
(), (\rtf-control-word0 ).
33Example 5. Custom RTF File RTF Control Words -
Title and Data Step
- ods escapechar ''
- title1 'R/RTF"\ul " Title contains underlined
text' - data rtfcontrol
- a "The text uses RTF control words "
- 'R"\i italic text \i0 "' ' regular
text ' - 'R"\ul underlined text \ul0 "'
- 'R"\strike strike text \strike0 "'
- run
- ods rtf file c\how\gupta\rtf_control.rtf'
- proc print datartfcontrol
- run ods rtf close
Be careful to match all quotes
34Example 5. Custom RTF File RTF Control Words -
Title and Data Step
RTF
Look what SAS can do - it really works!
35Example 6. Summary Table Using In-line Formatting
Text in RTF files
- OPTIONS ORIENTATIONPORTRAIT nodate center
- ODS ESCAPECHAR /
required / - / signals start of non SAS code - tags ex.
super a/ - ODS RTF FILE 'C\how\gupta\table1.rtf'
- STYLE MINIMAL / Basic MS Word table, no
color / - BODYTITLE
- SAS Procedure(s)
- ODS RTF CLOSE
Be very careful of ODS BODYTITLE option!
36Customize RTF File Header/Footer Sections -
Titles
- Place font attributes before the text to apply
- Syntax is different from footnote and SAS
Procedures PRINT, REPORT, and TABULATE - In version 8.2, Page X of Y feature requires
print review/print to take affect. - The following syntax is required
- "Page \field\\fldinst PAGE
\of\\field\\fldinst NUMPAGES "
37Example 6. Customize RTF File Header/Footer
Sections - Titles
- Title fontarial bold
- "Table 1. Baseline Table Sex, Racesuper a
Page pageof " - Font fontltcouriertimesarialhelve
ticagt - ltboldmedianlightgt
- ltitalicromanslantgt
- Height height8pt
- Justify jltleftrightcentergt
- Superscript super text
Subscript sub text - Page X of Y pageof (V 9.0)
-
Face
Weight
Style
38Customize RTF File Header/Footer Sections -
Footnotes
- Place font attributes before the text to apply
- Syntax is same as SAS Procedures PRINT, REPORT,
and TABULATE - Remember to turn off style just like like turning
off ODS
39Example 6. Customize RTF File Header/Footer
Sections - Footnotes
- Footnote1 Sfont_facearial font_styleitalic
super aRace Non-White consists of Black,
Hispanic, and Native AmericanS - Footnote2 Sfont_facearial font_styleitalicP
rogram /stat/druga/program1.sas S - Font
- Sfont_facearialtext S
- Sfont_weightboldtext S
- Sfont_styleitalictext S
Face
Weight
Style
40Applying Style Syntax in Proc Tabulate
- PROC TABULATE style / Style for all
data cells / -
- class /style / Style for column
and row header / - var / style / Style for analysis
variable heading / - table style
/ Style for entire table / - / boxstyle
/ Style for box label / - run
41Example 6. Customize RTF File Using PROC
TABULATE
- let mystyle str(font_face"arial"
font_weightbold) - (PROC FORMAT value gender, race, pctpct quit)
- PROC TABULATE datademog missing formchar'
-----------' - stylefont_face" courier"
-
- class gender race drug/stylemystyle
- format gender gender. race race.
- table (gender race), drug' '
- (n'N'f7. pctnltgender racegt' '
fpctpct. ) - / boxlabel'Baseline '
- stylemystyle rts43
- run
42Example 6. Summary Table Output Using PROC
TABULATE
RTF
Arial, Bold
Courier
43Example 7. Customize RTF File Using PROC
TABULATE
- OPTIONS ORIENTATIONLANDSCAPE nodate center
- let mystyle str(font_face"arial"
font_weightbold) - PROC TABULATE datademog missing formchar'
-----------' - stylefont_face" courier"
-
- class gender race drug/stylemystyle
- classlev gender race drug/stylemystyle
- format gender gender. race race.
- keyword n pctn/stylemystyle
- table (gender race), drug' '
- (n'N'f7. pctnltgender racegt' '
fpctpct. ) - / boxlabel'Baseline '
- stylemystyle rts43
- run
44Example 7. Summary Table Output Using PROC
TABULATE w/ CLASSLEV and KEYWORD
RTF
Arial, Bold
Arial, Bold
45Customize RTF File Using PROC PRINT
-
- PROC PRINT style()
- (header, data, obs,
obshead, table) - / all headers, data, obs column, obs
column header, data table / - var / style() (data, header)
-
/ separate var statements / - id / style() (data, header)
- sum / style() (data, header, total)
- run
46Example 8a. Customize RTF File Using PROC PRINT
- ODS RTF FILE 'C\how\gupta\table3.rtf' STYLE
MINIMAL BODYTITLE - PROC PRINT datademog (obs5) noobs
- style(header) font_face"arial"
font_weightbold - style(data) font_face"arial"
- var patient drug gender race age height weight
- fomat gender gender. race race.
- run
- ODS RTF Close
47Example 8a. Customize RTF File Using PROC PRINT
RTF
Arial, Bold
Arial
48Example 8b. Table with 2 Columns
- ODS RTF FILE 'C\how\gupta\table3.rtf' STYLE
MINIMAL COLUMNS2 - PROC PRINT datademog
- style(header) font_face"arial"
font_weightbold - style(data) font_face"arial"
- var patient drug gender race age height weight
- fomat gender gender. race race.
- run
- ODS RTF Close
49Example 8b. Table with 2 Columns
RTF
50Summary Where to Go From Here
- Programmer, Statistician, Manager
- Power Flexibility
- Customizing Output
- Creating Excel Files
- RTF-control words
- Applying Style Syntax in Proc Tabulate and Proc
Print
51SAS ODS Technology for Todays Decision Makers
- ODS RESOURCES
- The Complete Guide to the SAS Output Delivery
System Version 8 - http//www.sas.com/rnd/base/index-ods-resources.ht
ml - Quick Results with the Output Delivery System
- Output Delivery System The Basics
- Chevell Parker, Generating Custom Excel
Spreadsheets Using ODS
52SAS ODS Technology for Todays Decision Makers
- Sunil.Gupta_at_Quintiles.com
- Quintiles
ODS
53- SAS ODS Technology for Todays Decision Makers
- Sunil Gupta
- Quintiles