Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

30
Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011

Transcript of Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

Page 1: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

Managing Your SAS Output with the Document Procedure

PhilaSUG MeetingMarch 15, 2011

Page 2: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

Outline

• Review of Output Delivery System

• What is the ODS Document and what can it do for you?

• Quick-Start course

• Listing and Replaying Documents

• Additional Capabilities – quick overview only

• How to find out more

• Q&A

Page 3: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

Scenario – Which one is my analysis for TODAY's meeting?

Page 4: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 4

What can be stored in a Document?

SAS/Graph Graphics

ODS Statistical Graphics SAS Data Sets (small)

Text Notes

“As you can see from the previous output, the clustering is quite strong”

SAS Procedural Output

Page 5: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

Using The Document Procedure is EASY• Save Output Now:ODS DOCUMENT

NAME=philasug.mystuff;<your sas code>

ODS DOCUMENT CLOSE;

• Replay Output Laterproc document

name=philasug.mystuff; replay; run; quit;

Page 6: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11

Two Approaches to Learning PROC Document• “Google Approach”

• Use no folders, and use the WHERE statement to create searches to specify which output is replayed

• Good for beginners, so you can focus on ODS rather than file management

• Approach used in this presentation

• “Yahoo Approach”• Use lots of folders, set them up before you even start adding output to the

document

• Direct output to the propre folder with the ODS Document command

• Combination• Most people will use a combination of these!

Page 7: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 7

What sort of Output does the Document Store?

To replay output, you need all three. The Document saves the first two, and some formats.

Template

Informatio

nODS Table or

Graph

Formats

Titles & Footnotes

Object Notes

Context

Page 8: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 8

How the Output Delivery System Works Without The

ODS Document

Page 9: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 9

With the ODS Document

Page 10: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 10

Organization of the ODS Document Like a directory Output from Each SAS

Procedure has its own Each folder Named for its

procedure Can have more than one

folder with PROC REG output, for instance

Each output object and directory has a path-name, derived from ODS naming conventions

Page 11: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 11

Talking to the Output Delivery System Every output has an ODS pathname

ods trace on;

proc univariate data=sashelp.class; by sex; var height age;run;

ods trace off;

Page 12: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 12

Ods Stores data in the document based on the ODS Pathname

Output Added: (you can find this message in the Sas LOG)-------------Name: MomentsLabel: MomentsTemplate: base.univariate.MomentsPath: Univariate.ByGroup1.Height.Moments-------------

Terminology of the ODS part IIAll four of these terms, Name, Label, Template, and Path can be used to search the document,hence worth learning

Example ODS Trace output: Use it to teach you ODS names of output you commonly use.

Page 13: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 13

The ODS Document Statement, Building a Document

ods document name=<docname><(access-mode)>

<DIR=(path specification) <LABEL=“label text”>

PROC ….

DATA Steps with ODS output

ODS Document Close;

ODS Document exclude/exclude statements;

ODS Include PARAMETERESTIMATES;Proc reg;...

Page 14: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11

Access Modes

READ (read-only) access

WRITE – not what it sounds!

- ERASES the ENTIRE document, then inserts the new data. Should be called Over-write mode.

Update – The default

Will continually append new output after old output

Page 15: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11

Quick Aside – deleting a Document

proc datasets lib=nesug mtype=itemstor; delete firstdoc;quit;

/* can also rename */

SAS ODS Documents are of type ITEMSTORE, which when abbreviated to eight letters is ITEMSTOR. The only place you need to know this fact is for this delete.

For most document management tasks, use PROC DOCUMENT, NOT PROC DATASETS.

Page 16: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 16

List contents of document (LIST) commad Replay documents (REPLAY) command Create Labels for each output object Create, Manage, and Delete Folders Create Shortcuts to subfolders, Notes, Titles all

without re-running the original analysis Make changes to graphs (SAS 9.3)

Jobs of the Document Procedure

Page 17: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 17

Invoking The Document Procedure

PROC DOCUMENT Name=<docname><(access mode)> <Label=>;

Page 18: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 18

LIST Command PROC DOCUMENT Name=<docname>

<(access mode)> <DIR=> <Label=>;

LIST paths / options ;

Run ;

Quit ;

Levels= n | ALLDetailsBYGroups

Most Useful Options

MUST HAVE!

Page 19: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 19

Output from LIST; with no options

One directory (pathname) for each PROC called

Levels=1 is the default

Automatically generated Sequence Numbersensure all objects have unique names

Name of base directory (default is root directory)

Page 20: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 20

LIST / DETAILS LEVELS=ALL;

Page 21: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 21

What Happens when you Replay?

To replay output, you need both. The power of PROC Document comes from the ability to change information in the Pink Square to modify appearance while leaving blue square alone.

Style!

Fonts

Highlighting

Fill Colors

Actual Template

Stored in Document

TemplateInformation

ODS Table or Graph Formats

Titles & Footnotes

Object Notes

Context

TemplateInformationTemplateInformation

ODS Table or GraphODS Table or Graph Formats

Titles & Footnotes

Object Notes

ContextFormats

Titles & Footnotes

Object Notes

Context

Document Says: “I need Base.Sas.Reg to complete my work.

ODS Says “I have that on file!”

Page 22: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 22

REPLAYING OutputProc document name=;

Replay;

Run;

Quit;

Page 23: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11

Replaying The Documentods html body=<whatever> style=BarrettsBlue; /*for SH */

ods rtf body=<whatever> style=Printer;

ods listing; /* needed for EG, since not turned on by default */

proc document name=nesug.firstdoc (read);

list / order=alpha;

replay / dest=(listing rtf html);

run;

quit;

ods _all_ close;

2

1

3

Page 24: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 24

Restricting Output HIDE Command

HIDE PATH; prevents the path and all its subfolders from being replayed

HIDE REG#1;

UNHIDE Command Opposite of Mr. Jekkyl

Page 25: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 25

The WHERE statement New as in 9.2 Can condition replay based on

Dates of creation or modification Name of object (and this is why ODS Trace is so helpful) Label of object Pathname of Object By-Groups variables(if original code used BY groups)

Can also be used on file management commands, so we can conditionally LIST.

Page 26: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 26

WHERE Statement Variables_CDATE_ Creation Date

_CDATETIME_ Creation Date/Time

_CTIME_ Creation Time

_LABELPATH_ Path Name, in Label format

_MDATE_,_MDATETIME_,_MTIME_

Similar to Cdate* variables, but cover modification time.

_NAME_ Name of current entry. The name is the rightmost entry of the path name.

_PATH_ Pathname of current entry

_SEQNO_ Sequence number of current entry

_TYPE_ Type of object: TABLE or DIRECTORY

Variable name The variable name used as a by group. This is valid only when BY group analysis is used to create the output.

Page 27: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 27

WHERE Statement ExamplesExample 4. 1 Searching By Path

list ^(where=(_path_ ? "Height")) / levels=all;

run;/* quit */

Example 4. 2 Tables Only

list ^(where=(_type_ = "Table")) / levels=all;

Example 4. 3 Tables with BY Groups

list ^ (where=(_type_ eq 'Table')) / levels=all bygroups;

^ represents the current directory. Usually can be dropped, but the WHERE statement needs a token before it.

Page 28: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 28

WHERE Statement Examples

Example 4 By Group Example:Female Only

list ^ (where=(_type_ = "Table") & (sex="F"))/ levels=all bygroups;

Example 5 Univariate Output, Created Before September 6, 2010.

list Univariate#1(where=(_cdate < '06Sep2010'd));

Example 4. 6 Using ODS Name objects.

list reg#2(where=(_NAME_in ('FitStatistics','ParameterEstimates'));

Page 29: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 29

Make your own directories

Create copies and links for faster reporting

Modify Titles, formats, headers, columns, styles without altering output or rerunning original analysis

Combining several reports into one for easy comparison

Enhance output with traffic lighting, but without modifying the original data or defining new formats.s

Intermediate Topics

Page 30: Managing Your SAS Output with the Document Procedure PhilaSUG Meeting March 15, 2011.

3/15/11 30

Finding out More Andrew Karp - “A Peek at the Document

Procedure” - SGF 2007 #224 SAS Support ODS Document Tip Sheethttp://support.sas.com/rnd/base/ods/scratch/document-tips.pdf

New from SAS Press:

PROC Document using SAS – Available for Pre-order at NESUG 2011