WINKS SDAStatistical Software
Affordable. Reliable. Relevant.
Free Trial
www.texasoft.com
 


Masters in Applied Statistics
Degree in Dallas


BeSmartNotes

BeSmartNotes
Handy SAS Reference Sheets

 

 

SAS Tutorial Menu

Main Tutorial Menu

Numbers

Controlling SAS output using ODS
See www.stattutorials.com/SASDATA for files mentioned in this tutorial

These SAS statistics tutorials briefly explain the use and interpretation of standard statistical analysis techniques for Medical, Pharmaceutical, Clinical Trials, Marketing or Scientific Research. The examples include how-to instructions for SAS Software.

Controlling SAS output using ODS

ODS, or Output Delivery System, is a method within SAS of controlling the output from SAS Procedures. ODS began with version 8 and is now in production in version 9.1 (but still under development)

ODS can be used to output results using several types of format including:

ODS can also be used to

Not every option available in ODS is covered in this introduction to ODS. However, most SAS users should find that the information discussed will cover most output needs.

A Simple ODS Example

This example shows how you can utilize ODS quickly and simply. Following this example, we will look at options for using ODS that will give you more control over the output.

Suppose you want to create output to be saved in Microsoft Word. 

Using the following code (ODS1.SAS)

proc univariate data=sasdata2.somedata;

histogram time1 /cfill=SKYblue;

run;

 

you get the standard SAS output (listing) shown (partially) below. The graph is in a separate window, and colors available for the graph are limited.

 

 

                                    The UNIVARIATE Procedure

                                   Variable:  ID  (ID Number)

 

                                            Moments

 

                N                          50    Sum Weights                 50

                Mean                   374.22    Sum Observations         18711

                Std Deviation      167.498314    Variance            28055.6853

                Skewness           -0.2716195    Kurtosis            -1.3081517

                Uncorrected SS        8376759    Corrected SS        1374728.58

                Coeff Variation    44.7593165    Std Error Mean      23.6878388

 

 

                                   Basic Statistical Measures

 

                         Location                    Variability

 

                     Mean     374.2200     Std Deviation          167.49831

                     Median   403.5000     Variance                   28056

                     Mode        .         Range                  503.00000

                                           Interquartile Range    310.00000

 

... etc (output truncated)

 

The graph output is:

 

Histogram


By adding a simple ODS command to the code, as shown here: (ODS2.SAS)

 

ODS RTF;

proc univariate data=sasdata2.somedata;

histogram time1 /cfill=skyblue;

run;

ODS RTF CLOSE;

 

The ODS RTF; command turns on the ODS output in “Rich Text Format” which is compatible with Word.  The ODS RTF CLOSE; command turns off the ODS output.  The output is opened in a Microsoft Word document as show here (partial output)

 

Moments
N

50

Sum Weights

50

Mean

374.22

Sum Observations

18711

Std Deviation

167.498314

Variance

28055.6853

Skewness

-0.2716195

Kurtosis

-1.3081517

Uncorrected SS

8376759

Corrected SS

1374728.58

Coeff Variation

44.7593165

Std Error Mean

23.6878388

 

This output is in standard Word tables for text output, and also includes the previous graph in the same Word file.

 

Note that SAS initially saves the output in to an “.RTF” file. You can resave the output as a “.DOC” file to make it into a standard Word document by selecting (in Word) File/Save As… and choosing the “Files of Type” as “.doc”.)

 

 

Defining the ODS Output Type and Destination

 

The syntax of the ODS command is

 

ods output-format <options>;

 

The default SAS output location is the normal “listing” which appears in the Output window. This output can be turned on using the command:

 

ODS LISTING;
 

and turned off using

 
ODS LISTING CLOSE;
 

To turn on any other output type simply use the command

 

ODS OUTPUT-FORMAT;

 

For example

 

ODS HTML;

 

The turn the output off use the CLOSE option:

 

ODS HTML CLOSE;

 

Usually, when you are using one of the other output types you may want to turn off the default listing first, output to your selected type, then turn the listing option back on.  For example:

 

ODS LISTING CLOSE;

ODS RTF;

    * SOME PROCEDURES…;

ODS RTF CLOSE;

ODS LISTING;

 

The RTF listing appears in the SAS Results Viewer and in the case of RTF output, SAS also prompts you for a filename which allows you to store the information into a specific RTF file

 

Output ODS to a Specific File

 

One of the most useful <OPTIONS>  is the ability to direct the output directly into a specific file. The following examples show how you can “open” the output into a specific type of file.

 

ods html body='HTML-file-pathname.html';
ods pdf file='PDF-file-pathname.pdf';
ods rtf file='RTF-file-pathname.rtf';
ods ps file='PS-file-pathname.ps';

 

Notice that the HTML output uses BODY= and the others use FILE=.  HTML output can also be output to frames, but that is not discussed here. (Technically, the FILE= option also works for HTML, but if you decide on using other HTML options (such as frames) it is a good idea to stick with the BODY=option.)

 

For example, to send data to an HTML file named C:\RESEARCH\OUTPUT.HTM you could use the syntax:

 

ODS HTML BODY= ‘C:\RESEARCH\OUTPUT.HTM’;

 

after running whatever SAS PROCS whose output you want to capture in the file, you turn off thIS ODS output using the command

 

ODS HTML CLOSE;

 

In a program you would typically first turn off the default listing, open the ODS output, run procedures, close ODS and reopen the standard listing:

 

ODS LISTING CLOSE;

ODS HTML FILE= 'C:\RESEARCH\OUTPUT.HTM';

PROC PRINT;

PROC MEANS;

*AND SO ON…;

ODS HTML CLOSE;

ODS LISTING;

 

If you leave off the destination as in

 

ODS PDF;

*. . .some procedures;

ODS CLOSE PDF;

 

or

 

ODS RTF;

*. . .some procedures;

ODS CLOSE RTF;

 

You will prompted to enter an output filename (or the results will go into the SAS Results viewer).

 

 

Controlling Output Style

 

To control the style of the SAS output you can specify the option

 

      STYLE=STYLE-TYPE;

 

For example (to use a style called ‘Barretsblue’)

 

      ODS RTF STYLE=BARRETTSBLUE;

      * ...some procedures;

      ODS RTF CLOSE;

 

 

So, for example, using the same program as above with a STYLE option (MODIFIED ODS2.SAS)

 

ODS RTF STYLE=BarrettsBlue;

PROC UNIVARIATE DATA=SASDATA2.SOMEDATA ;

HISTOGRAM TIME1 /CFILL=SKYBLUE;

RUN;

ODS RTF CLOSE;

 

Produces tables that are formatted with the “Barrettblue” style:

 

Moments
N

50

Sum Weights

50

Mean

374.22

Sum Observations

18711

Std Deviation

167.498314

Variance

28055.6853

Skewness

-0.2716195

Kurtosis

-1.3081517

Uncorrected SS

8376759

Corrected SS

1374728.58

Coeff Variation

44.7593165

Std Error Mean

23.6878388

 

 

Listing ODS Styles

 

To produce a list of the current SAS styles available, use the code:

 

PROC TEMPLATE; LIST STYLES; RUN;

 

Here is a (partial) listing of the results:  

                         

 

                            Obs    Path                       Type

                            ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

                             1     Styles                     Dir

                             2     Styles.Analysis            Style

                             3     Styles.Astronomy           Style

                             4     Styles.Banker              Style

                             5     Styles.BarrettsBlue        Style

                             6     Styles.Beige               Style

                             7     Styles.Brick               Style

                             8     Styles.Brown               Style

                             9     Styles.Curve               Style

                            10     Styles.D3d                 Style

                            11     Styles.Default             Style

                            12     Styles.EGDefault           Style

                            13     Styles.Education           Style

                            14     Styles.Electronics         Style

                            15     Styles.Festival            Style

                            16     Styles.FestivalPrinter     Style

                            17     Styles.Gears               Style

                            18     Styles.Journal             Style

                            19     Styles.Magnify             Style

                            20     Styles.Meadow              Style

                            21     Styles.MeadowPrinter       Style

                            22     Styles.Minimal             Style

                            23     Styles.Money               Style

                            24     Styles.NoFontDefault       Style

                            25     Styles.Normal              Style

                            26     Styles.NormalPrinter       Style

                            27     Styles.Printer             Style

                            28     Styles.Rsvp                Style

                            29     Styles.Rtf                 Style

                            30     Styles.Sasweb              Style

                            31     Styles.Sasweb2             Style

                            And so on...

Putting it together

 

Here is a simple example, first using RTF output: (ODS3.SAS)

 

* DEFINE WHERE LISTING WILL GO;

ODS RTF FILE='C:\RESEARCH\ODS.RTF' STYLE=SCIENCE;

* CLOSE THE NORMAL OUTPUT LISTING;

ODS LISTING CLOSE;

PROC MEANS DATA=SASDATA2.SOMEDATA;

TITLE 'ODS HTML Example';

RUN;

PROC BOXPLOTS; PLOT AGE*GP;

RUN;

* CLOSE THE RTF OUTPUT;

ODS RTF CLOSE;

* REOPEN THE NORMAL LISTING;

ODS LISTING;

RUN;

 

This code produces the following output – all in the same RTF/Word format file:

 

Variable

Label

N

Mean

Std Dev

Minimum

Maximum

ID
AGE
TIME1
TIME2
TIME3
TIME4
STATUS
SEX

ID Number
Age on Jan 1, 2000
Baseline
6 Months
12 Months
24 Months
Socioeconomic Status

50
50
50
50
50
50
50
50

374.2200000
10.4600000
21.2680000
27.4400000
30.4920000
30.8380000
3.9400000
0.4000000

167.4983143
2.4261332
1.7169551
2.6590623
3.0255942
3.5307333
1.3311036
0.4948717

101.0000000
4.0000000
17.0000000
21.3000000
22.7000000
21.2000000
1.0000000
0

604.0000000
15.0000000
24.2000000
32.3000000
35.9000000
36.1000000
5.0000000
1.0000000

 

(Note: We’ll see a better ODS version of box plots later…)

 

Using the HTML ODS destination requires a little extra information. In the listing below (ODS3a.SAS) notice that instead of FILE= you use BODY= to specify the file destination. Also, if there are graphs involved you may need to split the filename between a GPATH= statement that specifies the destination folder for graphs and a BODY= statement that specifies the destination filename. (ODS3a.SAS)

 

* DEFINE WHERE LISTING WILL GO; Box and Whiskers Plot

ODS HTML BODY='ODS.HTML' GPath="C:\RESEARCH" STYLE=SCIENCE;

* CLOSE THE NORMAL OUTPUT LISTING;

ODS LISTING CLOSE;

PROC MEANS DATA=SASDATA2.SOMEDATA;

TITLE 'ODS HTML Example';

RUN;

PROC BOXPLOTS; PLOT AGE*GP;

RUN; * CLOSE THE HTML OUTPUT;

ODS HTML CLOSE;

* REOPEN THE NORMAL LISTING;

ODS LISTING;

RUN;

 

A final example is used to produce output in the PDF output (for Adobe Reader). This output option allows you to create output that can be viewed across computer platforms as long as the have the (free) Adobe reader. (ODS3b.SAS)

 

* DEFINE WHERE LISTING WILL GO;

ODS PDF FILE='C:\RESEARCH\ODS.PDF' STYLE=SCIENCE;

* CLOSE THE NORMAL OUTPUT LISTING;

ODS LISTING CLOSE;

PROC MEANS DATA=SASDATA2.SOMEDATA;

TITLE 'ODS PDF Example';

RUN;

PROC BOXPLOTS; PLOT AGE*GP;

RUN;

* CLOSE THE PDF OUTPUT;

ODS PDF CLOSE;

* REOPEN THE NORMAL LISTING;

ODS LISTING;

RUN;

 

Which produces the following output (in Adobe)

 

SAS ODS PDF Output

 

 

Other ODS Benefits: Clearer Output

 

Some standard SAS listings output are difficult to read. Outputting in PDF or HTML often improves the readability as well as the “looks” of the output.

 

T-Test Example Using Listing (no ODS)

 

(ODS4.SAS)

 

DATA TTEST;

INPUT GROUP OBS @@;

CARDS;

   1   23.00   1   23.00   1   32.00   1   24.00   1   25.00

   2   25.00   2   46.00   2   56.00   2   45.00   2   56.00

   2   55.00

;

PROC TTEST;

     CLASS GROUP;

     VAR OBS;

     Title 'T-Test Example';

RUN;

Produces the following somewhat confusing listing:

    

                                          Statistics

 

                             Lower CL          Upper CL  Lower CL           Upper CL

Variable  GROUP           N      Mean    Mean      Mean   Std Dev  Std Dev   Std Dev  Std Err

OBS                       5    20.705    25.4    30.095    2.2656   3.7815    10.866   1.6912

           1

OBS                       6    34.619  47.167    59.715    7.4636   11.957    29.326   4.8814

           2

OBS       Diff (1-2)           -34.45  -21.77     -9.08    6.3706   9.2618    16.908   5.6083

 

 

                                            T-Tests

 

             Variable    Method           Variances      DF    t Value    Pr > |t|

             OBS         Pooled           Equal           9      -3.88      0.0037

             OBS         Satterthwaite    Unequal      6.16      -4.21      0.0053

 

 

                                     Equality of Variances

 

                 Variable    Method      Num DF    Den DF    F Value    Pr > F

                 OBS         Folded F         5         4      10.00    0.0445

 


 

Add ODS to the code:

 

ODS RTF;

PROC TTEST;

     CLASS GROUP;

     VAR OBS;

     Title 'T-Test Example';

RUN;

ODS RTF CLOSE;

tmp1

 

T-Tests
Variable Method Variances

DF

t Value

Pr > |t|

OBS Pooled Equal

9

-3.88

0.0037

OBS Satterthwaite Unequal

6.16

-4.21

0.0053

 

Equality of Variances
Variable Method

Num DF

Den DF

F Value

Pr > F

OBS Folded F

5

4

10.00

0.0445

 

This output is at least in a table that makes finding each value a little easier.

 

Creating an interactive web-page “Drill Down Chart” using SAS ODS

 

Start with a regular GCHART (or GPLOT) Graph: (ODS5.SAS)

 

data barchart;

input group @@;

datalines;

1 2 3 4 3 2 3 2 1 1 1 1 2 3 2 4 3 2 1 4 3 2 3 4 3

;

PROC GCHART;

      HBAR group/ DISCRETE;

      RUN; QUIT;

 

This yields a standard (non-interactive) SAS plot:

SAS Bar Chart

Suppose for each “group” you wanted to report some other set of statistics. Here is how you can create a primary graph (bar chart) where you can click on each bar to reveal more information. First the three “result” pages are created, then the primary page/chart is created, all in html. (ODS5A.SAS)

 

* CREATE OUTPUT FOR EACH SECONDARY ANALYSIS;

DATA TEST1;*............................................FOR GROUP A;

SET SAS_ODS.ADV_EXAMPLE;

IF GROUP="A";

ODS HTML BODY="GPA.HTM" GPATH="C:\RESEARCH\";

PROC MEANS MAXDEC=2 N MEAN STD;

TITLE 'Summary for Group A';

RUN;

DATA TEST2;*............................................FOR GROUP B;

SET SAS_ODS.ADV_EXAMPLE;

IF GROUP="B";

ODS HTML FILE="GPB.HTM"; GPATH="C:\RESEARCH\";

PROC MEANS MAXDEC=2 N MEAN STD;

TITLE 'Summary for Group B';

RUN;

DATA BARCHART;SET SAS_ODS.ADV_EXAMPLE;

LENGTH HTMLLINK $40;

IF GROUP="A" THEN HTMLLINK='HREF="GPA.HTM"';

IF GROUP="B" THEN HTMLLINK='HREF="GPB.HTM"';

IF GROUP="C" THEN HTMLLINK='HREF="http:\\www.cnn.com"'; * LINK TO ANY WEB PAGE;

ODS HTML FILE="GCHART.HTM" GPATH="C:\RESEARCH\";

ODS LISTING CLOSE;

PROC GCHART;

      HBAR GROUP/ HTML=HTMLLINK;

         TITLE 'Summary information for each group.';

RUN; QUIT;

ODS HTML CLOSE;

ODS LISTING;

 

The following initial bar graph is displayed. Note: This plot appears in the SAS Results Viewer, but it is also stored on disk as GCHART.HTM.

 

 

HBAR chart of GROUP with HTML Links

 


Click on the top bar in the graph and the following information appears:

 

 

 

Summary for Group A

 

The MEANS Procedure

Variable

Label

N

Mean

Std Dev

AGE

TIME_EXPOSED

STATUS

DIAGNOSED

 

AGE

TIME_EXPOSED

STATUS

DIAGNOSED

 

11

11

11

11

 

10.36

21.18

3.09

0.36

 

2.87

2.15

1.51

0.50

 

 

 

Go back and click on the other bars to see that that also display the summary information for that group.  The third group displays the designated web site (which you would more logically specify as something pertinent to the meaning of the bar.)

 

This process could be used to create drill down graphs that could be placed on an Internet website to allow users to look at the data “behind” a graph.
 

Select specific tables of the output using ODS

 

Suppose you want to perform a 2x2 Chi Square analysis and suppress the Fisher’s Exact Test results. For the following program: (ODS6.SAS)

 

DATA;

   DO A = 1 TO 2;

       DO B = 1 TO 2;

          INPUT WT @@;

          OUTPUT;

       END;

   END;

DATALINES;

12 15

18 3

;

ods html;

PROC FREQ;

   WEIGHT WT;

   TABLES A*B /CHISQ;

   TITLE 'CHI-SQUARE ANALYSIS FOR A 2X2 TABLE';

RUN;
ods html close;

The normal (HTML) output is:

 

CHI-SQUARE ANALYSIS FOR A 2X2 TABLE

 

The FREQ Procedure

Frequency
Percent
Row Pct
Col Pct

 

Table of A by B

A

B

Total

1

2

1

12
25.00
44.44
40.00

15
31.25
55.56
83.33

27
56.25
 
 

2

18
37.50
85.71
60.00

3
6.25
14.29
16.67

21
43.75
 
 

Total

30
62.50

18
37.50

48
100.00

 

 

Statistics for Table of A by B

 

Statistic

DF

Value

Prob

Chi-Square

1

8.5841

0.0034

Likelihood Ratio Chi-Square

1

9.1893

0.0024

Continuity Adj. Chi-Square

1

6.9136

0.0086

Mantel-Haenszel Chi-Square

1

8.4053

0.0037

Phi Coefficient

 

-0.4229

 

Contingency Coefficient

 

0.3895

 

Cramer's V

 

-0.4229

 

 

Fisher's Exact Test

Cell (1,1) Frequency (F)

12

Left-sided Pr <= F

0.0036

Right-sided Pr >= F

0.9996

 

 

Table Probability (P)

0.0032

Two-sided Pr <= P

0.0061

Sample Size = 48

 

To select specific tables of the output you use the “SELECT” statement:

 

ODS (type) select (list of tables);

 

But how do you know the SAS table names? Run this code: (ODS6A.SAS)

 

 

ods trace on;

PROC FREQ;

   WEIGHT WT;

   TABLES A*B /CHISQ;

   TITLE 'CHI-SQUARE ANALYSIS FOR A 2X2 TABLE';

RUN;

ods trace off;

 

Run this and look in your LOG window to see the SAS table names:

 

Output Added:

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

Name:       CrossTabFreqs

Label:      Cross-Tabular Freq Table

Data Name:

Path:       Freq.Table1.CrossTabFreqs

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

 

Output Added:

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

Name:       ChiSq

Label:      Chi-Square Tests

Template:   Base.Freq.ChiSq

Path:       Freq.Table1.ChiSq

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

 

Output Added:

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

Name:       FishersExact

Label:      Fisher's Exact Test

Template:   Base.Freq.ChisqExactFactoid

Path:       Freq.Table1.FishersExact

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

 

With this information you can limit your output to only the CrossTabFreqs and ChiSq tables using the following code: (ODS6B.SAS)

 

ods listing close;

ods html; *turn the html output on first;

ods html select crosstabfreqs chisq;

PROC FREQ;

   WEIGHT WT;

   TABLES A*B /CHISQ;

   TITLE 'CHI-SQUARE ANALYSIS FOR A 2X2 TABLE';

RUN;

ods html close;

ods listing;

 

This results in the same output as above but without the Fisher’s table.

 

Note: You can also use an EXCLUDE statement instead of the SELECT statement in the ODS command to exclude specific tables.

 


 

Using ODS Graphics in SAS Procedures

 

SAS ODS Graphics allows you to create graphs that are specifically design for particular procedures. These graphics are initiated with the statements

 

ODS GRAPHICS ON;

 

* include procs here;

 

ODS GRAPHICS OFF;

 

For example, in PROC CORR, to request a matrix of scatterplots use the following code: (ODS7.SAS)

 

ods html;

ods graphics on;

ods listing close;

proc corr data=SASDATA.SOMEDATA plots=matrix;

     var time1-time4;

run;

ods graphics off;

ods html close;

ods listing;

 

The produces the following HTML output:

 

 

 

The CORR Procedure

4 Variables:

TIME1 TIME2 TIME3 TIME4

 

Simple Statistics

Variable

N

Mean

Std Dev

Sum

Minimum

Maximum

Label

TIME1

50

21.26800

1.71696

1063

17.00000

24.20000

TIME1

TIME2

50

27.44000

2.65906

1372

21.30000

32.30000

TIME2

TIME3

50

30.49200

3.02559

1525

22.70000

35.90000

TIME3

TIME4

50

30.83800

3.53073

1542

21.20000

36.10000

TIME4

 

 

 

 

Pearson Correlation Coefficients, N = 50
Prob > |r| under H0: Rho=0

 

TIME1

TIME2

TIME3

TIME4

TIME1
TIME1

1.00000

0.76396
<.0001

0.68572
<.0001

0.82628
<.0001

TIME2
TIME2

0.76396
<.0001

1.00000

0.83405
<.0001

0.57305
<.0001

TIME3
TIME3

0.68572
<.0001

0.83405
<.0001

1.00000

0.64860
<.0001

TIME4
TIME4

0.82628
<.0001

0.57305
<.0001

0.64860
<.0001

1.00000

 

Matrix of Scatterplots from SAS ODS

 

 

SAS ODS Example with Regression

 

Here is an example of creating a scatterplot with fitted line as a part of a regression analysis. This illustrates the default graphics for the REG procedure. (ODS8.SAS)

 

DATA ART;

INPUT SUBJECT $ CREATE TASK @@;

DATALINES;

AE    28    4.5 FR      35    3.9 HT      37    3.9 IO      50    6.1

DP    69    4.3 YR      84    8.8 QD      40    2.1 SW      65    5.5

DF    29    5.7 ER      42    3.0 RR      51    7.1 TG      45    7.3

EF    31    3.3 TJ      40    5.2

;

   ods html;

   ods graphics on;

   proc reg;

      MODEL TASK=CREATE;

        TITLE 'Example regression with an ODS GRAPH';

   run;

   quit;

   ods graphics off;

   ods html close;

*......................PRODUCING AN "OLD" TYPE GRAPH;

SYMBOL1 V=STAR I=RL;   * definitions for plot *;

PROC GPLOT; PLOT TASK*CREATE;

title "Old Graph";

RUN;

QUIT;

 

tmp3


 

Add the ODS options for output…

 

   ods html;

   ods graphics on;

   proc reg;

      MODEL TASK=CREATE;

        TITLE 'Example regression with an ODS GRAPH';

   run;

   quit;

   ods graphics off;

   ods html close;

 

Example regression with an ODS GRAPH

 

The REG Procedure

Model: MODEL1

Dependent Variable: TASK

Number of Observations Read

14

Number of Observations Used

14

 

Analysis of Variance

Source

DF

Sum of
Squares

Mean
Square

F Value

Pr > F

Model

1

13.70112

13.70112

5.33

0.0396

Error

12

30.85388

2.57116

 

 

Corrected Total

13

44.55500

 

 

 

 

Root MSE

1.60348

R-Square

0.3075

Dependent Mean

5.05000

Adj R-Sq

0.2498

Coeff Var

31.75213

 

 

 

Parameter Estimates

Variable

DF

Parameter
Estimate

Standard
Error

t Value

Pr > |t|

Intercept

1

2.16452

1.32141

1.64

0.1273

CREATE

1

0.06253

0.02709

2.31

0.0396

 


Example regression with an ODS GRAPH

 

The REG Procedure

Model: MODEL1

Dependent Variable: TASK

Fit Diagnostics from SAS ODS

 

Residual Plots

 

 

 

Analysis of Variance Example (using PROC GLM)

 

The following is an example of ANOVA output from ODS. (ODS9.SAS) This example uses PROC GLM (You could use PROC ANOVA for the same results.) Notice the difference in the box plots from this option and the previous PROC BOXPLOT shown earlier.

 

DATA ACHE;

INPUT BRAND RELIEF @@;

CARDS;

1 24.5 1 23.5 1 26.4 1 27.1 1 29.9

2 28.4 2 34.2 2 29.5 2 32.2 2 30.1

3 26.1 3 28.3 3 24.3 3 26.2 3 27.8

;

ODS LISTING CLOSE;

ODS RTF;

ODS GRAPHICS ON;

PROC GLM DATA=ACHE;

    CLASS BRAND;

    MODEL RELIEF=BRAND;

    MEANS BRAND/TUKEY;

TITLE 'Compare RELIEF across MEDICINES  - ANOVA Example';

run;

ODS RTF CLOSE;

ODS GRAPHICS OFF;

ODS LISTING;

 

This produces the follow output (some output not shown):

 

R-Square

Coeff Var

Root MSE

RELIEF Mean

0.543303

7.751664

2.162714

27.90000

 

Source

DF

Anova SS

Mean Square

F Value

Pr > F

BRAND

2

66.77200000

33.38600000

7.14

0.0091

 


Box Plots from SAS ODS

 

Tukey's Studentized Range (HSD) Test for loss

 

Alpha

0.05

Error Degrees of Freedom

12

Error Mean Square

4.677333

Critical Value of Studentized Range

3.77278

Minimum Significant Difference

3.649

 

 

Means with the same letter are not significantly different.

Tukey Grouping

Mean

N

BRAND

A

30.880

5

2

 

 

 

 

B

26.540

5

3

B

 

 

 

B

26.280

5

1

 


 

Creating Output Statistics from ODS

 

You can capture output from procedures and put that information in to a SAS output file. As before, you can find out what output is created using TRACE. (ODS10.SAS)

 

ods trace on; * DISCOVER NAMES OF OUTPUT COMPONENTS;

   proc reg;

      MODEL TASK=CREATE;

   run;

ods trace off;

 

Resulting output is:

 

Output Added:

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

Name:       NObs

Label:      Number of Observations

Template:   Stat.Reg.NObs

Path:       Reg.MODEL1.Fit.TASK.NObs

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

 

Output Added:

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

Name:       ANOVA

Label:      Analysis of Variance

Template:   Stat.REG.ANOVA

Path:       Reg.MODEL1.Fit.TASK.ANOVA

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

 

Output Added:

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

Name:       FitStatistics

Label:      Fit Statistics

Template:   Stat.REG.FitStatistics

Path:       Reg.MODEL1.Fit.TASK.FitStatistics

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

 

Output Added:

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

Name:       ParameterEstimates

Label:      Parameter Estimates

Template:   Stat.REG.ParameterEstimates

Path:       Reg.MODEL1.Fit.TASK.ParameterEstimates

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

 


 

Using the output name you’ve discovered from TRACE, output the info you want using the code

 

ods output ParameterEstimates=estimates;

 

which tells SAS to output those estimates to the SAS file work.estimates. (ODS10A.SAS)

 

DATA ART;

INPUT SUBJECT $ CREATE TASK @@;

DATALINES;

AE    28    4.5 FR      35    3.9 HT      37    3.9 IO      50    6.1

DP    69    4.3 YR      84    8.8 QD      40    2.1 SW      65    5.5

DF    29    5.7 ER      42    3.0 RR      51    7.1 TG      45    7.3

EF    31    3.3 TJ      40    5.2

;

*CREATE A SAS DATASET CONTAINING ESTIMATES;

ODS OUTPUT PARAMETERESTIMATES=ESTIMATES;

   PROC REG;

      MODEL TASK=CREATE;

   RUN;

ODS OUTPUT CLOSE;

* Print out results;

ODS HTML;

PROC PRINT DATA=ESTIMATES;

TITLE "Output Data Set";

RUN;

      ODS HTML CLOSE;

 

Which results in the following output (this is the contents (PROC PRINT) of the file “work.estimate” – containing the regression estimates.

 

In the SAS Viewtable, the resulting data set looks like this:

 

Obs

Model

Dependent

Variable

DF

Estimate

StdErr

tValue

Probt

1

MODEL1

TASK

Intercept

1

2.16452

1.32141

1.64

0.1273

2

MODEL1

TASK

CREATE

1

0.06253

0.02709

2.31

0.0396

 

 

Using this technique you can output virtually any information from a SAS procedure, which enables you to use that information in another procedure or combine it into another data set. For example, to use this information to calculate residuals you could use the following technique: (ODS10B.SAS)

 

* THIS CODE CREATES A DATA SET (COEFFICIENTS) CONTAINING THE

* PARAMETERS OF THE REGRESSION EQUATION;

proc transpose data=estimates

       out=COEFFICIENTS prefix=COEF;

       var estimate;

       run;

 

*THIS CODE COMBINES THE COEFFICIENT AND ORIGINAL DATA

       AND CALCULATES THE RESIDUALS;

data predict; set art;

if _N_=1 then set coefficients;

intercept=coef1;

slope=coef2;

predicted=intercept+create*slope;

residual=task-predicted;

keep subject create task intercept slope predicted residual;

run;

 

* DISPLAY RESULTS;

ods listing close;

ods RTF;

proc print data=predict; var subject create task predicted residual;

run;

ods RTF close;

ods listing;

 

Obs SUBJECT CREATE TASK predicted residual

1

AE

28

4.5

3.91546

0.58454

2

FR

35

3.9

4.35320

-0.45320

3

HT

37

3.9

4.47826

-0.57826

4

IO

50

6.1

5.29120

0.80880

5

DP

69

4.3

6.47934

-2.17934

6

YR

84

8.8

7.41734

1.38266

7

QD

40

2.1

4.66586

-2.56586

8

Etc…        

 

 

 

(See the working data sets named ESTIMATES and PREDICT.)

 

Current Procedures Supporting ODS Graphics

The following SAS procedures support ODS Graphics in SAS 9.1:

Base SAS

  • CORR

SAS/ETS

  • ARIMA

  • AUTOREG

  • ENTROPY

  • EXPAND

  • MODEL

  • SYSLIN

  • TIMESERIES

  • UCM

  • VARMAX

  • X12

SAS High-Performance Forecasting

  • HPF

SAS/STAT

  • ANOVA

  • CORRESP

  • GAM

  • GENMOD

  • GLM

  • KDE

  • LIFETEST

  • LOESS

  • LOGISTIC

  • MI

  • MIXED

  • PHREG

  • PRINCOMP

  • PRINQUAL

  • REG

  • ROBUSTREG

 

In SAS 9.1, the ODS destinations that support ODS Graphics include HTML, LATEX, PRINTER, and RTF.

 

End of tutorial

See http://www.stattutorials.com/SAS