25
Output Delivery System (ODS) in SAS STAT:5201 Week 10 - Lecture 2 1 / 25

Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

Output Delivery System (ODS) in SAS

STAT:5201

Week 10 - Lecture 2

1 / 25

Page 2: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS output delivery system in SAS

Purpose:To allow for more flexibility in the kind of SAS output that the usercan produce.

Benefit to consultant:For many analyses, the ODS options in SAS can make you muchmore efficient because it allows you to ‘capture’ results in a formother than the usual format that we see in the output window.

There are many ways to use ODS statements (see diagram nextslide), but my present experience has been limited to using ODS tosave specific parts of the output from a procedure, such as PROCMIXED, to a SAS data set.

ODS has been very useful in this sense, and therefore, I’ll presentsome examples here for using ODS in this manner.

2 / 25

Page 3: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS output delivery system in SAS

Diagram provided by SAS:

ODS Concepts Components of SAS Output 23

Figure 2.1 ODS Processing: What Goes in and What Comes Out

ODS Processing: What Goes In and What Comes Out

TableDefinition

DataComponent

OutputObject

DOCUMENT LISTING OUTPUT HTML MARKUP PRINTER RTF

SAS Formatted Destinations Third-Party Formatted Destinations

DocumentOutput

ListingOutput

SASData Set

HTML3.2Output

SASTAGSETS*

User-definedTAGSETS

RTFOutput

MSWindowsPrinters

PS PCL PDF

ODSDestinations

ODSOutputs

+

Table 2.1 * List of Tagsets That SAS Supplies and Supports

CHTML CSV CSVALL CSVBYLINE

DEFAULT DOCBOOK EXCELXP HTML4

HTMLCSS HTMLPANEL IMODE MSOFFICE2K

PHTML PYX RTF SASREPORT

WML WMLOLIST XHTML

Table 2.2 * Additional Diagnostic Tagsets that SAS Supports

EVENT_MAP NAMEDHTML SHORT_MAP STYLE_DISPLAY

STYLE_POPUP TEXT_MAP TPL_STYLE_LIST TPL_SYLE_MAP

Note: There are also preproduction tagsets. These tagsets can be found at http://support.sas.com and are not yet supported by SAS.

The Output Object, contains both the results of the procedure or DATAstep and information about how to render the results. 3 / 25

Page 4: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS output delivery system in SAS

Diagram provided by SAS:

ODS Concepts Components of SAS Output 23

Figure 2.1 ODS Processing: What Goes in and What Comes Out

ODS Processing: What Goes In and What Comes Out

TableDefinition

DataComponent

OutputObject

DOCUMENT LISTING OUTPUT HTML MARKUP PRINTER RTF

SAS Formatted Destinations Third-Party Formatted Destinations

DocumentOutput

ListingOutput

SASData Set

HTML3.2Output

SASTAGSETS*

User-definedTAGSETS

RTFOutput

MSWindowsPrinters

PS PCL PDF

ODSDestinations

ODSOutputs

+

Table 2.1 * List of Tagsets That SAS Supplies and Supports

CHTML CSV CSVALL CSVBYLINE

DEFAULT DOCBOOK EXCELXP HTML4

HTMLCSS HTMLPANEL IMODE MSOFFICE2K

PHTML PYX RTF SASREPORT

WML WMLOLIST XHTML

Table 2.2 * Additional Diagnostic Tagsets that SAS Supports

EVENT_MAP NAMEDHTML SHORT_MAP STYLE_DISPLAY

STYLE_POPUP TEXT_MAP TPL_STYLE_LIST TPL_SYLE_MAP

Note: There are also preproduction tagsets. These tagsets can be found at http://support.sas.com and are not yet supported by SAS.

The ODS destination of OUTPUT produces SAS data sets. The ODSdestination of LISTING, HTML, and PRINTER destinations produces eachof those, respectively.

4 / 25

Page 5: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Skull thicknessFitting the same model at numerous locations on a skull(or genes), and retaining the LSMeans for each location.

The graphic of interest (219 skull locations):

female

front of skull

skul

l(<--

front

to b

ack-

->)

0.4

0.6

0.8

11.2

CF.5.1 CF.5.6 CF.5.11

male

front of skull

skul

l(<--

front

to b

ack-

->)

0.4

0.6

0.8

11.2

CF.5.1 CF.5.6 CF.5.11

At each location, we fit the same model. It included 3 factors of interest(sex, region, age as high/med/low) and 3 covariates...

5 / 25

Page 6: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Skull thickness

Model fit at one specific skull location #219

proc mixed data=loc219;

class Sex Region Age_fa;

model y= Sex Region Age_fa

Glabella_Opisthocranion

Vertex_Basion

Euryon_Euryon;

run;

In order to present a graphic of the predicted thicknesses over theentire skull for each sex (averaged over region and age), we wanted tocapture the LSmeans for ‘sex’ at each location.

6 / 25

Page 7: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Skull thickness

The LSMean for females represents the expected thickness for the‘average female’.

The LSMean is a ‘marginal mean’ or ‘population mean’, and can bethought of as the predicted value for females averaging over allregions, averaging over all ages, and any other variables in the model.

We first sorted the data by location and used the by statement tofit the same model at every location, and we also included thelsmeans statement...

7 / 25

Page 8: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Skull thickness

proc sort data=skulls3;

by location;

run;

proc mixed data=skulls3;

by location;

class Sex Region Age_fa;

model y= Sex Region Age_fa

Glabella_Opisthocranion

Vertex_Basion

Euryon_Euryon;

lsmeans Sex;

run;

This obviously lead to lots of output in the visible output window.

There are many things of interest in the output, but presently, I onlywant to capture the LSMeans for ‘sex’, and I want to capture it forEVERY location.

8 / 25

Page 9: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Skull thickness

Some output from location 219 is below:

9 / 25

Page 10: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example - trace on/off: Skull thickness

In order to use ODS to capture output, you first need to know what is‘available’ to be captured (label names are very specific).

We can use the ODS trace on and the ODS trace off statementsto provide a listing of things that are available to be captured.

We will run our model at one location to get this listing...

ODS trace on;

proc mixed data=loc219;

class Sex Region Age_fa;

model y= Sex Region Age_fa

Glabella_Opisthocranion

Vertex_Basion

Euryon_Euryon/solution;

lsmeans sex;

run;

ODS trace off;

10 / 25

Page 11: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example trace output: Skull thickness

The listing will appear in the log box:Output Added:

-------------

Name: ModelInfo

Label: Model Information

Template: Stat.Mixed.ModelInfo

Path: Mixed.ModelInfo

-------------

Output Added:

-------------

Name: ClassLevels

Label: Class Level Information

Template: Stat.Mixed.ClassLevels

Path: Mixed.ClassLevels

-------------

Output Added:

-------------

Name: Dimensions

Label: Dimensions

Template: Stat.Mixed.Dimensions

Path: Mixed.Dimensions

-------------11 / 25

Page 12: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example trace output: Skull thickness

Output Added:

-------------

Name: NObs

Label: Number of Observations

Template: Stat.Mixed.NObs

Path: Mixed.NObs

-------------

Output Added:

-------------

Name: CovParms

Label: Covariance Parameter Estimates

Template: Stat.Mixed.CovParms

Path: Mixed.CovParms

-------------

Output Added:

-------------

Name: FitStatistics

Label: Fit Statistics

Template: Stat.Mixed.FitStatistics

Path: Mixed.FitStatistics

-------------

12 / 25

Page 13: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example trace output: Skull thickness

Output Added:

-------------

Name: SolutionF

Label: Solution for Fixed Effects

Template: Stat.Mixed.SolutionF

Path: Mixed.SolutionF

-------------

Output Added:

-------------

Name: Tests3

Label: Type 3 Tests of Fixed Effects

Template: Stat.Mixed.Tests3

Path: Mixed.Tests3

-------------

Output Added:

-------------

Name: LSMeans

Label: Least Squares Means

Template: Stat.Mixed.LSMeans

Path: Mixed.LSMeans

-------------

13 / 25

Page 14: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Skull thickness

I’m presently interested in the output with the label ‘Least SquaresMeans’ (though I was also interested in the ‘Type 3 Tests of FixedEffects’).

NOTE: what you request in the SAS model statements affect what isavailable, such as including /solution will allow you to capture theparameter estimates in the model.

Next, remove the ODS trace on and ODS trace off statementsand replace them with ODS statements requesting that the desiredvalues be saved in a new SAS data set. Then, re-run your code.

I have also suppressed some of the output to the output window.

14 / 25

Page 15: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example - capture LSmeans: Skull thickness

ods output LSMeans=lsmeans_sex;

proc mixed data=skulls3 noinfo noitprint;

by location;

class Sex Region Age_fa;

model y= Sex Region Age_fa

Glabella_Opisthocranion

Vertex_Basion

Euryon_Euryon;

lsmeans Sex;

run;

ods output close;

15 / 25

Page 16: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Skull thickness

The data set contains some things not of interest, so I often removeunneeded variables.

l E

o s

c E R A t S t

a f e g i t V P

t f g e m d a r

O i e S i _ a E l o

b o c e o f t r D u b

s n t x n a e r F e t

1 1 Sex 1 _ 0.3674 0.01932 120 19.02 <.0001

2 1 Sex 2 _ 0.4049 0.01835 120 22.06 <.0001

3 2 Sex 1 _ 0.4887 0.02082 120 23.47 <.0001

4 2 Sex 2 _ 0.5017 0.01978 120 25.36 <.0001

5 3 Sex 1 _ 0.4435 0.01916 120 23.14 <.0001

6 3 Sex 2 _ 0.4609 0.01820 120 25.32 <.0001

data lsmeans_sex; set lsmeans_sex;

keep location Effect Sex Estimate;

run; 16 / 25

Page 17: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example and Proc Export: Skull thickness

PROC EXPORT DATA= lsmeans_sex

OUTFILE= "Y:\lsmeans_sex.csv"

DBMS=CSV REPLACE;

RUN;

17 / 25

Page 18: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Skull thickness

These LSMeans (or predicted values) were then used to produce thegraphic of skull thicknesses for each sex using the R package‘spatstat’.

We did the same for Region...Austr

front of skull

skul

l(<--

front

to b

ack-

->)

0.2

0.4

0.6

0.8

11.2

1.4

CF.5.1 CF.5.6 CF.5.11

Can.Grnld

front of skull

skul

l(<--

front

to b

ack-

->)

0.2

0.4

0.6

0.8

11.2

1.4

CF.5.1 CF.5.6 CF.5.11

China

front of skull

skul

l(<--

front

to b

ack-

->)

0.2

0.4

0.6

0.8

11.2

1.4

CF.5.1 CF.5.6 CF.5.11

Egypt

front of skull

skul

l(<--

front

to b

ack-

->)

0.2

0.4

0.6

0.8

11.2

1.4

CF.5.1 CF.5.6 CF.5.11

Scand

front of skull

skul

l(<--

front

to b

ack-

->)

0.2

0.4

0.6

0.8

11.2

1.4

CF.5.1 CF.5.6 CF.5.11

India

front of skull

skul

l(<--

front

to b

ack-

->)

0.2

0.4

0.6

0.8

11.2

1.4

CF.5.1 CF.5.6 CF.5.11

Asia.oth

front of skull

skul

l(<--

front

to b

ack-

->)

0.2

0.4

0.6

0.8

11.2

1.4

CF.5.1 CF.5.6 CF.5.11

Japan

front of skull

skul

l(<--

front

to b

ack-

->)

0.2

0.4

0.6

0.8

11.2

1.4

CF.5.1 CF.5.6 CF.5.11

Sub.Sah

front of skull

skul

l(<--

front

to b

ack-

->)

0.2

0.4

0.6

0.8

11.2

1.4

CF.5.1 CF.5.6 CF.5.11

Russia

front of skull

skul

l(<--

front

to b

ack-

->)

0.2

0.4

0.6

0.8

11.2

1.4

CF.5.1 CF.5.6 CF.5.11

18 / 25

Page 19: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Skull thickness

And for Age..young

skul

l(<--

front

to b

ack-

->)

0.4

0.6

0.8

11.2

CF.5.1 CF.5.6 CF.5.11

middle

skul

l(<--

front

to b

ack-

->)

0.4

0.6

0.8

11.2

CF.5.1 CF.5.6 CF.5.11

old

skul

l(<--

front

to b

ack-

->)

0.4

0.6

0.8

11.2

CF.5.1 CF.5.6 CF.5.11

19 / 25

Page 20: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Capturing output with ODS

So, using ODS is a two-step process

Use the trace statements to see what is available to capture.

Re-run the model after including the ODS statements expressing whatyou want to capture.

20 / 25

Page 21: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Creating LaTex code for tables from SAS

To include tables in LaTeX code, you can use the Listing output withthe Verbatim environment, or the HTML output as a graphic.

But another option is to have SAS generate LaTeX code that can beembedded in your .tex file.

Steps:1 Save the output table as a SAS data set using ODS OUTPUT.2 Use ODS TAGSETS.SIMPLELATEX with the PROC PRINT statement

to generate the LaTeX code chunk.3 Include the table in your .tex code.

21 / 25

Page 22: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Creating LaTex code for tables from SAS

Example (Creating LaTeX code chunks in SAS)

Fit a 1-way ANOVA and generate the marginal means for the factor levels,and include the bounds for the 95% confidence intervals. Save the meanestimates and information in ‘CItable’.

ods output LSMeans=CItable;

proc glm data=circuits plot=diagnostics;

class type;

model time=type;

lsmeans type/CL;

run;

quit; /* <--- VERY IMPORTANT LINE */

ods output close;

NOTE: PROC GLM is an ‘interactive’ procedure, and you will want toquit that procedure before you generate your ODS output.

22 / 25

Page 23: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Creating LaTex code for tables from SAS

Example (Creating LaTeX code chunks in SAS)

The created SAS data set and the original printed output table don’t likeexactly the same, but they’re close:

Original SAS output Created SAS data set

23 / 25

Page 24: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Creating LaTex code for tables from SAS

Example (Creating LaTeX code chunks in SAS)

Use ODS TAGSETS with PROC PRINT to send the LaTeX code chunk toa file:

ods tagsets.simplelatex file="Y:\my.tex" (notop nobot)

stylesheet="sas.sty"(url="sas");

proc print data=CItable noobs label;

run;

ods tagsets.simplelatex close;

24 / 25

Page 25: Output Delivery System (ODS) in SAShomepage.divms.uiowa.edu/.../notes/ODS_output_slides.pdf · 2020. 4. 3. · support.sas.com and are not yet supported by SAS. The ODS destination

ODS Example: Creating LaTex code for tables from SAS

Example (Creating LaTeX code chunks in SAS)

LaTeX code created:

And after including the package ‘longtable’ in my LaTeX preamble andcompiling, it looks like this:

http://support.sas.com/rnd/base/ods/odsmarkup/latex.html 25 / 25