The following examples display typical uses of the Output Delivery System.
This example demonstrates how you can use the ODS HTML statement to display your output in hypertext markup language (HTML).
The following statements create the data set scores , which contains the golf scores for boys and girls in a physical education class. The TTEST procedure is then invoked to compare the scores.
The ODS HTML statement specifies the name of the file to contain the HTML output.
data scores; input Gender $ Score @@; datalines; f75 f76 f80 f77 f80 f77 f73 m82 m80 m85 m85 m78 m87 m82 ; run; ods html body='ttest.htm'; title 'Comparing Group Means'; proc ttest ; class Gender; var Score; run; ods html close;
By default, the SAS listing receives all output generated during your SAS run. In this example, the ODS HTML statement opens the HTML destination, and both destinations receive the generated output. Output 14.1.1 displays the results as they are rendered in the SAS listing.
Note that you must specify the following statement before you can view your output in a browser.
ods html close;
If you do not close the HTML destination, your HTML file may contain no output, or you may experience other unexpected results. Output 14.1.2 displays the file ttest.htm , which is specified in the preceding ODS HTML statement.
Comparing Group Means The TTEST Procedure Statistics Lower CL Upper CL Lower CL Upper CL Variable Class N Mean Mean Mean Std Dev Std Dev Std Dev Std Err Minimum Maximum Score f 7 74.504 76.857 79.211 1.6399 2.5448 5.6039 0.9619 73 80 Score m 7 79.804 82.714 85.625 2.028 3.1472 6.9303 1.1895 78 87 Score Diff (1-2) -9.19 -5.857 -2.524 2.0522 2.8619 4.7242 1.5298 T-Tests Variable Method Variances DF t Value Pr > t Score Pooled Equal 12 -3.83 0.0024 Score Satterthwaite Unequal 11.5 -3.83 0.0026 Equality of Variances Variable Method Num DF Den DF F Value Pr > F Score Folded F 6 6 1.53 0.6189
The following example uses ODS to display the output in HTML with a table of contents.
The data are from Pothoff and Roy (1964) and consist of growth measurements for 11 girls and 16 boys at ages 8, 10, 12, and 14.
data pr; input Person Gender $ y1 y2 y3 y4; y=y1; Age=8; output; y=y2; Age=10; output; y=y3; Age=12; output; y=y4; Age=14; output; drop y1-y4; datalines; 1 F 21.0 20.0 21.5 23.0 2 F 21.0 21.5 24.0 25.5 3 F 20.5 24.0 24.5 26.0 4 F 23.5 24.5 25.0 26.5 5 F 21.5 23.0 22.5 23.5 6 F 20.0 21.0 21.0 22.5 7 F 21.5 22.5 23.0 25.0 8 F 23.0 23.0 23.5 24.0 9 F 20.0 21.0 22.0 21.5 10 F 16.5 19.0 19.0 19.5 11 F 24.5 25.0 28.0 28.0 12 M 26.0 25.0 29.0 31.0 13 M 21.5 22.5 23.0 26.5 14 M 23.0 22.5 24.0 27.5 15 M 25.5 27.5 26.5 27.0 16 M 20.0 23.5 22.5 26.0 17 M 24.5 25.5 27.0 28.5 18 M 22.0 22.0 24.5 26.5 19 M 24.0 21.5 24.5 25.5 20 M 23.0 20.5 31.0 26.0 21 M 27.5 28.0 31.0 31.5 22 M 23.0 23.0 23.5 25.0 23 M 21.5 23.5 24.0 28.0 24 M 17.0 24.5 26.0 29.5 25 M 22.5 25.5 25.5 26.0 26 M 23.0 24.5 26.0 30.0 27 M 22.0 21.5 23.5 25.0 run; ods html body='mixed.htm' contents='mixedc.htm' frame='mixedf.htm'; proc mixed data=pr method=ml covtest asycov; class Person Gender; model y = Gender Age Gender*Age / s; repeated / type=un subject=Person r; run; ods html close;
The ODS HTML statement specifies three files. The BODY= argument specifies the file to contain the output generated from the statements that follow. The BODY= argument is required.
The CONTENTS= option specifies a file to contain the table of contents. The FRAME= option specifies a file to contain both the table of contents and the output. You open the FRAME= file in your browser to view the table of contents together with the generated output (see Output 14.2.1). Note that if you specify the ODS HTML statement with only the BODY= argument, no table of contents is created.
The MIXED procedure is invoked to fit the specified model. The resulting output is displayed in Output 14.2.1.
The table of contents displayed in Output 14.2.1 contains the descriptive label for each output table produced in the MIXED procedure step. You can select any label in the table of contents and the corresponding output will be displayed in the right-hand side of the browser window.
In order to select or exclude a table, or to render it as a SAS data set, you must first know its name. You can obtain the table names in several ways (see the section Using the Output Delivery System beginning on page 274 for more information).
This example uses the ODS TRACE statement with the LISTING option to obtain the names of the created output objects. By default, the ODS TRACE statement writes its information to the SAS log. However, you can specify the LISTING option to have the information interleaved with the procedure output in the SAS listing.
Suppose that you perform a randomized trial on rats that have been exposed to a carcinogen. You divide them into two groups and give each group a different treatment. In the following example, interest lies in whether the survival distributions differ between the two treatments . The data set Exposed contains four variables : Days (survival time in days from treatment to death), Status (censoring indicator variable: 0 if censored and 1 if not censored), Treatment (treatment indicator), and Sex (gender: F if female and M if male).
data Exposed; input Days Status Treatment Sex $ @@; datalines; 179 1 1 F 378 0 1 M 256 1 1 F 355 1 1 M 262 1 1 M 319 1 1 M 256 1 1 F 256 1 1 M 255 1 1 M 171 1 1 F 224 0 1 F 325 1 1 M 225 1 1 F 325 1 1 M 287 1 1 M 217 1 1 F 319 1 1 M 255 1 1 F 264 1 1 M 256 1 1 F 237 0 2 F 291 1 2 M 156 1 2 F 323 1 2 M 270 1 2 M 253 1 2 M 257 1 2 M 206 1 2 F 242 1 2 M 206 1 2 F 157 1 2 F 237 1 2 M 249 1 2 M 211 1 2 F 180 1 2 F 229 1 2 F 226 1 2 F 234 1 2 F 268 0 2 M 209 1 2 F ; ods trace on / listing; proc lifetest data=Exposed; time Days*Status(0); strata Treatment; run; ods trace off;
The purpose of these statements is to obtain the names of the ODS tables produced in this PROC LIFETEST run. The ODS TRACE ON statement writes the trace record of ODS output tables. The LISTING option specifies that the information is interleaved with the output and written to the SAS listing.
The LIFETEST procedure is invoked to perform the analysis, the SAS listing receives the procedure output and the trace record, and the trace is then disabled with the OFF option.
The LIFETEST Procedure Output Added: ------------- Name: ProductLimitEstimates Label: Product-Limit Estimates Template: Stat.Lifetest.ProductLimitEstimates Path: Lifetest.Stratum1.ProductLimitEstimates ------------- Stratum 1: Treatment = 1 Product-Limit Survival Estimates Survival Standard Number Number Days Survival Failure Error Failed Left 0.000 1.0000 0 0 0 20 171.000 0.9500 0.0500 0.0487 1 19 179.000 0.9000 0.1000 0.0671 2 18 217.000 0.8500 0.1500 0.0798 3 17 224.000* . . . 3 16 225.000 0.7969 0.2031 0.0908 4 15 255.000 . . . 5 14 255.000 0.6906 0.3094 0.1053 6 13 256.000 . . . 7 12 256.000 . . . 8 11 256.000 . . . 9 10 256.000 0.4781 0.5219 0.1146 10 9 262.000 0.4250 0.5750 0.1135 11 8 264.000 0.3719 0.6281 0.1111 12 7 287.000 0.3188 0.6813 0.1071 13 6 319.000 . . . 14 5 319.000 0.2125 0.7875 0.0942 15 4 325.000 . . . 16 3 325.000 0.1063 0.8938 0.0710 17 2 355.000 0.0531 0.9469 0.0517 18 1 378.000* . . . 18 0 NOTE: The marked survival times are censored observations. Summary Statistics for Time Variable Days Output Added: ------------- Name: Quartiles Label: Quartiles Template: Stat.Lifetest.Quartiles Path: Lifetest.Stratum1.TimeSummary.Quartiles ------------- Quartile Estimates Point 95% Confidence Interval Percent Estimate [Lower Upper) 75 319.000 262.000 325.000 50 256.000 255.000 319.000 25 255.000 217.000 256.000
The information obtained with the ODS TRACE ON statement enables you to request output tables by name. The examples that follow demonstrate how you can use this information to select, exclude, or create data sets from particular output tables.
You can use the ODS SELECT statement to deliver only the desired tables to ODS destinations. In the following example, the GLM procedure is used to perform an analysis on an unbalanced two-way experimental design.
data twoway; title "Unbalanced Two-way Design"; input Treatment Block y @@; datalines; 1 1 17 1 1 28 1 1 19 1 1 21 1 1 19 1 2 43 1 2 30 1 2 39 1 2 44 1 2 44 1 3 16 2 1 21 2 1 21 2 1 24 2 1 25 2 2 39 2 2 45 2 2 42 2 2 47 2 3 19 2 3 22 2 3 16 3 1 22 3 1 30 3 1 33 3 1 31 3 2 46 3 3 26 3 3 31 3 3 26 3 3 33 3 3 29 3 3 25 ; proc glm data=twoway; class Treatment Block; model y = Treatment Block; means Treatment; lsmeans Treatment; ods select ModelANOVA Means; ods trace on; ods show; run;
In the preceding statements, the GLM procedure is invoked to produce the output. The ODS SELECT statement specifies that only the two tables ModelANOVA and Means are to be delivered to the ODS destinations. In this example, no ODS destinations are explicitly opened. Therefore, only the default SAS listing receives the procedure output. The ODS SHOW statement displays the current overall selection list in the SAS log. The ODS TRACE statement writes the trace record of the ODS output objects to the SAS log.
ods select ModelANOVA Means; ods show; Current OVERALL select list is: 1. ModelANOVA 2. Means
Partial results of the ODS TRACE statement, which are written to the SAS log, are displayed in Output 14.4.2. Note that there are two tables having the name ModelANOVA, which are the Type I Model Anova and the Type III Model Anova tables. Similarly, there are two ODS tables having the name Means, which are the Means and the LS-means tables.
Output Added: ------------- Name: ClassLevels Label: Class Levels Template: STAT.GLM.ClassLevels Path: GLM.Data.ClassLevels ------------- . . . . Output Added: ------------- Name: ModelANOVA Label: Type I Model ANOVA Template: stat.GLM.Tests Path: GLM.ANOVA.y.ModelANOVA ------------- Output Added: ------------- Name: ModelANOVA Label: Type III Model ANOVA Template: stat.GLM.Tests Path: GLM.ANOVA.y.ModelANOVA ------------- NOTE: Means from the MEANS statement are not adjusted for other terms in the model. For adjusted means, use the LSMEANS statement. Output Added: ------------- Name: Means Label: Means Template: stat.GLM.Means Path: GLM.Means.Treatment.Means ------------- Output Added: ------------- Name: Means Label: Means Template: stat.GLM.LSMeans Path: GLM.LSMEANS.Treatment.Means
In the following statements, the ODS SHOW statement writes the current overall selection list to the SAS log. The QUIT statement ends the GLM procedure. The second ODS SHOW statement writes the selection list to the log after PROC GLM terminates. The ODS selection list is reset to ALL, by default, when a procedure terminates. For more information on ODS exclusion and selection lists, see the section Using the Output Delivery System beginning on page 274.
ods show; quit; ods show;
The results of the statements are displayed in Output 14.4.3. Before the GLM procedure terminates, the ODS selection list includes only the two tables, ModelANOVA and Means.
ods show; Current OVERALL select list is: 1. ModelANOVA 2. Means quit; NOTE: There were 33 observations read from the dataset WORK.TWOWAY. ods show; Current OVERALL select list is: ALL
The GLM procedure supports interactive run-group processing. Before the QUIT statement is executed, PROC GLM is active and the ODS selection list remains at its previous setting before PROC GLM was invoked. After the QUIT statement, when PROC GLM is no longer active, the selection list is reset to deliver all output tables.
The entire displayed output consists of the four selected tables (two ModelANOVA tables and two Means tables), as displayed in Output 14.4.4 and Output 14.4.5.
Unbalanced Two-way Design The GLM Procedure Dependent Variable: y Source DF Type I SS Mean Square F Value Pr > F Treatment 2 8.060606 4.030303 0.24 0.7888 Block 2 2621.864124 1310.932062 77.95 <.0001 Treatment*Block 4 32.684361 8.171090 0.49 0.7460 Source DF Type III SS Mean Square F Value Pr > F Treatment 2 266.130682 133.065341 7.91 0.0023 Block 2 1883.729465 941.864732 56.00 <.0001 Treatment*Block 4 32.684361 8.171090 0.49 0.7460
Unbalanced Two-way Design The GLM Procedure Level of --------------y-------------- Treatment N Mean Std Dev 1 11 29.0909091 11.5104695 2 11 29.1818182 11.5569735 3 11 30.1818182 6.3058414 Unbalanced Two-way Design The GLM Procedure Least Squares Means Treatment y LSMEAN 1 25.6000000 2 28.3333333 3 34.4444444
The following example demonstrates how you can use the ODS EXCLUDE statement to exclude particular tables from ODS destinations. This example also creates a SAS data set from the excluded table.
The data are from Hemmerle and Hartley (1973). The response variable consists of measurements from an oven experiment, and the model contains a fixed effect a and random effects b and a*b .
data hh; inputaby@@; datalines; 1 1 237 1 1 254 1 1 246 1 2 178 1 2 179 2 1 208 2 1 178 2 1 187 2 2 146 2 2 145 2 2 141 3 1 186 3 1 183 3 2 142 3 2 125 3 2 136 ; ods html body='mixed.htm' contents='mixedc.htm' frame='mixedf.htm'; ods exclude ParmSearch(persist); ods show;
The ODS HTML statement specifies the filenames to contain the output generated from the statements that follow.
The ODS EXCLUDE statement excludes the table ParmSearch from display. Although the table is excluded from the displayed output, the information contained in the ParmSearch table is graphically summarized in a later step.
The PERSIST option in the ODS EXCLUDE statement excludes the table for the entire SAS session or until you execute an ODS SELECT statement or an ODS EXCLUDE NONE statement. If you omit the PERSIST option, the exclusion list is cleared when the procedure terminates. The resulting exclusion list is displayed in Output 14.5.1.
ods exclude ParmSearch(persist); ods show; Current OVERALL exclude list is: 1. ParmSearch(PERSIST)
The following ODS OUTPUT statement outputs the table ParmSearch to a SAS data set called parms . The MIXED procedure is invoked and the model is fit. All output from the MIXED procedure, except the ParmSearch table, is delivered to the HTML destination and the SAS listing. The ODS SHOW statement again displays the overall current exclusion list.
ods output ParmSearch=parms; proc mixed data=hh asycov mmeq mmeqsol covtest; class a b; model y = a / outp=predicted; random b a*b; lsmeans a; parms (17 to 20 by 0.1) (.3 to .4 by .005) (1.0); run; ods show;
The results of the ODS SHOW statement, given after the MIXED procedure has terminated , are displayed in Output 14.5.2.
proc mixed data=hh asycov mmeq mmeqsol covtest; class a b; model y = a / outp=predicted; random b a*b; lsmeans a; parms (17 to 20 by 0.1) (.3 to .4 by .005) (1.0); run; ods show; Current OVERALL exclude list is: 1. ParmSearch(PERSIST)
Normally the ODS exclusion list is cleared at the conclusion of a procedure (for more information on ODS exclusion and selection lists, see the section Using the Output Delivery System on page 274). However, the PERSIST option in the preceding ODS EXCLUDE statement specifies that the ParmSearch table should remain in the exclusion list until the list is explicitly cleared (that is, when the ODS EXCLUDE NONE statement or an ODS SELECT statement is encountered ). Output 14.5.2 shows that the exclusion list remains in effect after PROC MIXED terminates.
The PERSIST option is useful when you want to exclude the same table in further analyses during your SAS session.
The ParmSearch table is contained in the parms data set (as specified in the ODS OUTPUT statement). The information is plotted with the G3D procedure in the following step:
proc g3d data=parms; plot CovP1*CovP2 = ResLogLike / ctop=red cbottom=blue caxis=black; run; ods html close;
The MIXED procedure output resulting from the preceding statements is displayed in Output 14.5.3. The table of contents shows the names for all of the output tables. The ParmSearch table is not listed in the table of contents because of the preceding ODS EXCLUDE statement.
The results of the G3D procedure is displayed in Output 14.5.4. The large amount of information contained in the table, which is excluded from display, can be summarized with a single plot.
The ODS OUTPUT statement creates SAS data sets from ODS tables. In the following example, the GENMOD procedure is invoked to perform Poisson regression and part of the resulting procedure output is written to a SAS data set.
Suppose the following insurance claims data are classified by two factors: age group (with two levels) and car type (with three levels).
data insure; input n c car$ age; ln = log(n); datalines; 500 42 small 1 1200 37 medium 1 100 1 large 1 400 101 small 2 500 73 medium 2 300 14 large 2 ;
In the data set insure , the variable n represents the number of insurance policyholders and the variable c represents the number of insurance claims. The variable car represents the type of car involved (classified into three groups) and the variable age is the age group of a policyholder (classified into two groups).
In the statements that follow, PROC GENMOD performs a Poisson regression analysis of these data with a log link function. Assume that the number of claims c has a Poisson probability distribution and that its mean, µ i , is related to the factors car and age .
The purpose of the following statements is to obtain the names of the output tables produced in this PROC GENMOD run. The ODS TRACE statement lists the trace record, and the SAS listing destination is closed so that no output is displayed.
ods trace on; ods listing close; proc genmod data=insure; class car age; model c = car age / dist = poisson link = log offset = ln obstats; run; ods trace off;
ods trace on; ods listing close; proc genmod data=insure; class car age; model c = car age / dist = poisson link = log offset = ln obstats; run; Output Added: ------------- Name: ModelInfo Label: Model Information Template: Stat.Genmod.ModelInfo Path: Genmod.ModelInfo ------------- . . . . NOTE: Algorithm converged. Output Added: ------------- Name: ParameterEstimates Label: Analysis Of Parameter Estimates Template: stat.genmod.parameterestimates Path: Genmod.ParameterEstimates ------------- NOTE: The scale parameter was held fixed. Output Added: ------------- Name: ObStats Label: Observation Statistics Template: Stat.Genmod.Obstats Path: Genmod.ObStats -------------
By default, the trace record is written to the SAS log, as displayed in Output 14.6.1. Note that you can alternatively specify that the information be interleaved with the procedure output in the SAS listing (see Example 14.3).
In the statements that follow, the ODS OUTPUT statement writes the ODS table ObStats to a SAS data set called myObStats . All of the usual data set options, such as the KEEP= or RENAME= option, can be used in the ODS OUTPUT statement. Thus, to create the myObStats data set so that it contains only certain variables of the ObStats table, you can use the data set options as follows .
ods output ObStats=myObStats (keep=car age pred rename=(pred=PredictedValue)); proc genmod data=insure; class car age; model c = car age / dist = poisson link = log offset = ln obstats; run;
The KEEP= option in the ODS OUTPUT statement specifies that only the variables car , age , and pred are written to the data set, and the pred variable is renamed to PredictedValue . The GENMOD procedure is again invoked. In order to limit the amount of displayed output, the SAS listing destination remains closed. When a destination is closed, it remains closed until it is explicitly reopened.
In the following statements, the output data set myObStats is sorted, and the SAS listing is reopened for output. The results are displayed in Output 14.6.2.
proc sort data=myObStats; by descending PredictedValue; run; ods listing; proc print data=myObStats noobs; title 'Values of Car, Age, and the Predicted Values'; run;
Values of Car, Age, and the Predicted Values Predicted car age Value small 2 107.2011 medium 2 67.025444 medium 1 42.974556 small 1 35.798902 large 2 13.773459 large 1 1.2265414
This example demonstrates how you can create an output data set with the ODS OUTPUT statement and also uses data set selection keywords to limit the output that ODS writes to a SAS data set.
The following data set, called Color , contains the eye and hair color of children from two different regions of Europe. The data are recorded as cell counts, where the variable Count contains the number of children exhibiting each of the 15 eye and hair color combinations.
data Color; input Region Eyes $ Hair $ Count @@; label Eyes ='Eye Color' Hair ='Hair Color' Region='Geographic Region'; datalines; 1 blue fair 23 1 blue red 7 1 blue medium 24 1 blue dark 11 1 green fair 19 1 green red 7 1 green medium 18 1 green dark 14 1 brown fair 34 1 brown red 5 1 brown medium 41 1 brown dark 40 1 brown black 3 2 blue fair 46 2 blue red 21 2 blue medium 44 2 blue dark 40 2 blue black 6 2 green fair 50 2 green red 31 2 green medium 37 2 green dark 23 2 brown fair 56 2 brown red 42 2 brown medium 53 2 brown dark 54 2 brown black 13 ;
In the statements that follow, the SAS listing is closed. The ODS OUTPUT statement creates the ChiSq table as a SAS data set called myStats . Note that you can obtain the names of the tables created by any SAS/STAT procedure in the individual procedure chapter or from the individual procedure section of the SAS online Help system. You can also determine the names of tables with the ODS TRACE statement (see Example 14.3 and Example 14.6).
The DROP= data set option excludes variables from the new data set. The WHERE= data set option selects particular observations for output to the new data set myStats , those that begin with Chi or Like .
ods listing close; ods output ChiSq=myStats (drop=Table where=(Statistic =: 'Chi' or Statistic =: 'Like'));
In the following statements, the Color data set is first sorted by the Region variable. The FREQ procedure is invoked to create and analyze a crosstabulation table from the two categorical variables Eyes and Hair , for each value of the variable Region .
No ODS destinations are open until the ODS LISTING statement is encountered just prior to the invocation of the PRINT procedure.
proc sort data=Color; by Region; run; proc freq data=Color order=data; weight Count; tables Eyes*Hair / testp=(30 12 30 25 3); by Region; title 'Hair Color of European Children'; run; ods listing; proc print data=myStats; run;
Output 14.7.1 displays the output resulting from the previous statements.
Hair Color of European Children Obs Region Statistic DF Value Prob 1 1 Chi-Square 8 12.6331 0.1251 2 1 Likelihood Ratio Chi-Square 8 14.1503 0.0779 3 2 Chi-Square 8 18.2839 0.0192 4 2 Likelihood Ratio Chi-Square 8 23.3021 0.0030
This example demonstrates how you can write multiple tables to a single data set using the PERSIST= option in the ODS OUTPUT statement. The PERSIST= option maintains ODS settings across RUN statements for procedures that support run-group processing. In the following analysis, the REG procedure is invoked and the covariance matrix of the estimates is output for two different models.
Consider the following population growth trends. The population of the United States from 1790 to 1970 is fit to linear and quadratic functions of time. Note that the quadratic term , YearSq , is created in the DATA step; this is done since polynomial effects such as Year * Year cannot be specified in the MODEL statement in PROC REG. The data are as follows:
title1 'Concatenating Two Tables into One Data Set'; title2 'US Population Study'; data USPopulation; input Population @@; retain Year 1780; Year=Year+10; YearSq=Year*Year; Population=Population/1000; datalines; 3929 5308 7239 9638 12866 17069 23191 31443 39818 50155 62947 75994 91972 105710 122775 131669 151325 179323 203211 ;
In the following statements, the REG procedure is invoked and the ODS OUTPUT statement with the PERSIST= option creates a data set with the COVB matrix (the covariance matrix of the estimates).
proc reg data=USPopulation; ods output covb(persist=run)=Bmatrix; var YearSq; model Population = Year / covb ; run;
The MODEL statement defines the regression model, and the COVB matrix is requested . The RUN statement executes the REG procedure and the model is fit, producing a covariance matrix of the estimates with two rows and two columns .
Concatenating Two Output Tables into One Data Set US Population Study The REG Procedure Model: MODEL1 Dependent Variable: Population Analysis of Variance Sum of Mean Source DF Squares Square F Value Pr > F Model 1 66336 66336 201.87 <.0001 Error 17 5586.29253 328.60544 Corrected Total 18 71923 Root MSE 18.12748 R-Square 0.9223 Dependent Mean 69.76747 Adj R-Sq 0.9178 Coeff Var 25.98271 Parameter Estimates Parameter Standard Variable DF Estimate Error t Value Pr > t Intercept 1 -1958.36630 142.80455 -13.71 <.0001 Year 1 1.07879 0.07593 14.21 <.0001
Concatenating Two Output Tables into One Data Set US Population Study The REG Procedure Model: MODEL1 Dependent Variable: Population Covariance of Estimates Variable Intercept Year Intercept 20393.138485 10.83821461 Year 10.83821461 0.0057650078
In the next step, the YearSq variable is added to the model and the model is again fit, producing a covariance matrix of the estimates with three rows and three columns.
add YearSq; print; run;
The results of the regression are displayed in Output 14.8.3.
Concatenating Two Output Tables into One Data Set US Population Study The REG Procedure Model: MODEL1.1 Dependent Variable: Population Analysis of Variance Sum of Mean Source DF Squares Square F Value Pr > F Model 2 71799 35900 4641.72 <.0001 Error 16 123.74557 7.73410 Corrected Total 18 71923 Root MSE 2.78102 R-Square 0.9983 Dependent Mean 69.76747 Adj R-Sq 0.9981 Coeff Var 3.98613 Parameter Estimates Parameter Standard Variable DF Estimate Error t Value Pr > t Intercept 1 20450 843.47533 24.25 <.0001 Year 1 22.78061 0.89785 25.37 <.0001 YearSq 1 0.00635 0.00023877 26.58 <.0001
Concatenating Two Output Tables into One Data Set US Population Study The REG Procedure Model: MODEL1.1 Dependent Variable: Population Covariance of Estimates Variable Intercept Year YearSq Intercept 711450.62602 757.2493826 0.2013282694 Year 757.2493826 0.8061328943 0.000214361 YearSq 0.2013282694 0.000214361 5.7010894E-8
The PERSIST=RUN option maintains the ODS selection list across RUN statements for procedures that support run-group processing. If the PERSIST=RUN option is omitted, the selection list is cleared when the RUN statement is encountered and only the first COVB matrix is selected. Because the PERSIST=RUN option is specified, the selection list remains in effect throughout the REG procedure step. This ensures that each of the COVB matrices is selected and output.
proc print; run;
The COVB Matrix Data Set, Using the PERSIST option Concatenating Two Output Tables into One Data Set Obs _Run_ Model Dependent Variable Intercept Year YearSq 1 1 MODEL1 Population Intercept 20393.138485 10.83821461 . 2 1 MODEL1 Population Year 10.83821461 0.0057650078 . 3 2 MODEL1.1 Population Intercept 711450.62602 757.2493826 0.2013282694 4 2 MODEL1.1 Population Year 757.2493826 0.8061328943 0.000214361 5 2 MODEL1.1 Population YearSq 0.2013282694 0.000214361 5.7010894E-8
Note that the two COVB matrices do not have the same variables. In previous ver-sions of SAS, the MATCH_ALL option along with a subsequent DATA step was needed to correctly get all of the variables in one data set. Now, the MATCH_ALL option is only needed if you want to make separate data sets for each table.
You can use the TEMPLATE procedure to modify the appearance of your displayed ODS tables. The following example, similar to that given in Olinger and Tobias (1998), creates output data sets using the ODS OUTPUT statement, modifies a template using PROC TEMPLATE, and displays the output data sets using the modified template.
The data set comes from a preclinical drug experiment (Cole and Grizzle 1966). In order to study the effect of two different drugs on histamine levels in the blood, researchers administer the drugs to 13 animals, and the levels of histamine in the animals blood is measured after 0, 1, 3, and 5 minutes. The response variable is the logarithm of the histamine level. The following statements create a SAS data set named Histamine that contains the experimental data.
title1 "Histamine Study"; data Histamine; input Drug . Depleted $ hist0 hist1 hist3 hist5; logHist0 = log(hist0); logHist1 = log(Hist1); logHist3 = log(hist3); logHist5 = log(Hist5); datalines; Morphine N .04 .20 .10 .08 Morphine N .02 .06 .02 .02 Morphine N .07 1.40 .48 .24 Morphine N .17 .57 .35 .24 Morphine Y .10 .09 .13 .14 Morphine Y .07 .07 .06 .07 Morphine Y .05 .07 .06 .07 Trimethaphan N .03 .62 .31 .22 Trimethaphan N .03 1.05 .73 .60 Trimethaphan N .07 .83 1.07 .80 Trimethaphan N .09 3.13 2.06 1.23 Trimethaphan Y .10 .09 .09 .08 Trimethaphan Y .08 .09 .09 .10 Trimethaphan Y .13 .10 .12 .12 Trimethaphan Y .06 .05 .05 .05 ;
In the analysis that follows, the GLM procedure is invoked to perform a repeated measures analysis, naming the drug and depletion status as between-subject factors in the MODEL statement and naming post-administration measurement time as the within-subject factor. For more information on this study and its analysis, refer to Example 32.7 in Chapter 32, The GLM Procedure.
The following ODS statement requests that two ODS tables be written to SAS data sets called HistWithin and HistBetween . The SAS listing is closed so that no output is displayed. The GLM procedure is invoked and the model is fit.
ods output MultStat = HistWithin BetweenSubjects.ModelANOVA = HistBetween; ods listing close; proc glm data=Histamine; class Drug Depleted; model LogHist0--LogHist5 = Drug Depleted Drug*Depleted / nouni; repeated Time 4 (0 1 3 5) polynomial / summary printe; run; quit;
All of the multivariate test results appear in the HistWithin data set. This is because all multivariate test tables are named MultStat, although they occur in different directories in the output directory hierarchy.
Note that, even though there are also other tables named ModelANOVA, the preceding ODS OUTPUT statement ensures that only the between-subject ANOVA appears in the HistBetween data set. The specific table is selected because of the additional specification of the partial path (BetweenSubjects) in which it occurs. For more information on names and qualified path names, see the discussion in the section Using the Output Delivery System beginning on page 274.
In the following statements, a new data set, temp1 , is created to contain the two data sets output in the preceding GLM run. They are displayed with no further processing.
ods listing; title2 'Listing of Raw Data Sets'; data temp1; set HistBetween HistWithin; run; proc print; run;
In order to reduce the amount of information displayed in Output 14.9.1, this example creates the following data set, HistTests . Only the observations from the raw data sets that are needed for interpretation are included. The variable Hypothesis in the HistWithin data set is renamed to Source , and the NumDF variable is renamed DF .
Histamine Study Listing of Raw Data Sets Hypothesis Obs Dependent Type Source DF SS MS FValue ProbF 1 BetweenSubjects 3 Drug 1 5.99336243 5.99336243 2.71 0.1281 2 BetweenSubjects 3 Depleted 1 15.44840703 15.44840703 6.98 0.0229 3 BetweenSubjects 3 Drug*Depleted 1 4.69087508 4.69087508 2.12 0.1734 4 BetweenSubjects 3 Error 11 24.34683348 2.21334850 _ _ 5 . . . . 24.03 0.0001 6 . . . . 24.03 0.0001 7 . . . . 24.03 0.0001 8 . . . . 24.03 0.0001 9 . . . . 5.78 0.0175 10 . . . . 5.78 0.0175 11 . . . . 5.78 0.0175 12 . . . . 5.78 0.0175 13 . . . . 21.31 0.0002 14 . . . . 21.31 0.0002 15 . . . . 21.31 0.0002 16 . . . . 21.31 0.0002 17 . . . . 12.48 0.0015 18 . . . . 12.48 0.0015 19 . . . . 12.48 0.0015 20 . . . . 12.48 0.0015 Obs Hypothesis Error Statistic Value NumDF DenDF 1 . . . 2 . . . 3 . . . 4 . . . 5 Time Error SSCP Matrix Wilks Lambda 0.11097706 3 9 6 Time Error SSCP Matrix Pillais Trace 0.88902294 3 9 7 Time Error SSCP Matrix Hotelling-Lawley Trace 8.01087137 3 9 8 Time Error SSCP Matrix Roys Greatest Root 8.01087137 3 9 9 Time_Drug Error SSCP Matrix Wilks Lambda 0.34155984 3 9 10 Time_Drug Error SSCP Matrix Pillais Trace 0.65844016 3 9 11 Time_Drug Error SSCP Matrix Hotelling-Lawley Trace 1.92774470 3 9 12 Time_Drug Error SSCP Matrix Roys Greatest Root 1.92774470 3 9 13 Time_Depleted Error SSCP Matrix Wilks Lambda 0.12339988 3 9 14 Time_Depleted Error SSCP Matrix Pillais Trace 0.87660012 3 9 15 Time_Depleted Error SSCP Matrix Hotelling-Lawley Trace 7.10373567 3 9 16 Time_Depleted Error SSCP Matrix Roys Greatest Root 7.10373567 3 9 17 Time_Drug_Depleted Error SSCP Matrix Wilks Lambda 0.19383010 3 9 18 Time_Drug_Depleted Error SSCP Matrix Pillais Trace 0.80616990 3 9 19 Time_Drug_Depleted Error SSCP Matrix Hotelling-Lawley Trace 4.15915732 3 9 20 Time_Drug_Depleted Error SSCP Matrix Roys Greatest Root 4.15915732 3 9
The renamed variables correspond to the variable names found in the HistBetween data set.
data HistTests; set HistBetween(where =(Source ^= "Error")) HistWithin (rename=(Hypothesis = Source NumDF=DF) where =(Statistic = "Hotelling-Lawley Trace")); run; proc print ; title2 Listing of Selections from the Raw Data Sets; run;
The amount of information contained in the HistTests is appropriate for interpreting the analysis ( Output 14.9.2). However, you can further modify the presentation of the data by applying a template to this combined test data. A template specifies how data should be displayed. The output from previous ODS TRACE ON statements (for example, Output 14.4.2) shows that each table has an associated template as well as a name. In particular, the template associated with PROC GLM s ANOVA table is called Stat.GLM.Tests .
Listing of Selections from the Raw Data Sets Hypothesis Obs Dependent Type Source DF SS MS 1 BetweenSubjects 3 Drug 1 5.99336243 5.99336243 2 BetweenSubjects 3 Depleted 1 15.44840703 15.44840703 3 BetweenSubjects 3 Drug*Depleted 1 4.69087508 4.69087508 4 . Time 3 . . 5 . Time_Drug 3 . . 6 . Time_Depleted 3 . . 7 . Time_Drug_Depleted 3 . . Obs FValue ProbF Error Statistic Value DenDF 1 2.71 0.1281 . . 2 6.98 0.0229 . . 3 2.12 0.1734 . . 4 24.03 0.0001 Error SSCP Matrix Hotelling-Lawley Trace 8.01087137 9 5 5.78 0.0175 Error SSCP Matrix Hotelling-Lawley Trace 1.92774470 9 6 21.31 0.0002 Error SSCP Matrix Hotelling-Lawley Trace 7.10373567 9 7 12.48 0.0015 Error SSCP Matrix Hotelling-Lawley Trace 4.15915732 9
You can use the Stat.GLM.Tests template to display the SAS data set HistTests ,as follows:
data _null_; title2 ';Listing of the Selections, Using a Standard Template'; set HistTests; file print ods=(template='Stat.GLM.Tests'); put _ods_; run;
The ODS= option in the FILE statement enables you to use the DATA step to display a data set as a table. You do this by specifying data columns and associated attributes, such as the template specification.
The PUT statement contains the _ODS_ keyword. The keyword instructs the PUT statement to send the data values for all columns (as defined in the ODS= option in the FILE statement) to the open ODS destinations. For more information on using ODS in the DATA step, refer to the SAS Output Delivery System User s Guide .
Histamine Study Listing of the Selections, Using a Standard Template Source DF SS Mean Square F Value Pr > F Drug 1 5.99336243 5.99336243 2.71 0.1281 Depleted 1 15.44840703 15.44840703 6.98 0.0229 Drug*Depleted 1 4.69087508 4.69087508 2.12 0.1734 Time 3 . . 24.03 0.0001 Time_Drug 3 . . 5.78 0.0175 Time_Depleted 3 . . 21.31 0.0002 Time_Drug_Depleted 3 . . 12.48 0.0015
The data set contains the appropriate information, and it is presented in an easily understandable format, using the Stat.GLM.Tests template.
Suppose that you now want to modify the template used to format the ANOVA tables in order to emphasize significant effects. The following statements provide an example of how you can use the TEMPLATE procedure to
redefine the format for the SS and Mean Square columns
include the table title and footnote in the body of the table
translate the missing values for SS and Mean Square in the rows corresponding to multivariate tests to asterisks (to refer to the footnote)
add a column depicting the level of significance
For detailed information on using the TEMPLATE procedure, refer to the chapter titled The Template Procedure in the SAS Output Delivery System User s Guide .
proc template; define table CombinedTests; parent=Stat.GLM.Tests; header "#Histamine Study##"; footer "#* - Test computed using Hotelling-Lawley trace"; column Source DF SS MS FValue ProbF Star; define SS; parent = Stat.GLM.SS; format = D7.3; translate _val_ = . into ' *'; end; define MS; parent = Stat.GLM.MS; format = D7.3; translate _val_ = . into ' *'; end; define Star; compute as ProbF; translate _val_ > 0.05 into "", _val_ > 0.01 into "*", _val_ > 0.001 into "**", _val_ <= 0.001 into "***"; pre_space=1 width=3 just=l; end; end; run;
The D w.s format, used in the preceding statements to redefine the SS and Mean Square columns, writes numbers in similar ranges with the same number of decimal places. In the format specification, w represents the width of the field and s represents the number of significant digits. Refer to the chapter on formats in the SAS Language Reference: Dictionary for detailed information.
The following statements display the HistTests data set using the customized template. The results are displayed in Output 14.9.4.
data _null_; title2 'Listing of the Selections, Using a Customized Template'; set HistTests; file print ods=(template='CombinedTests'); put _ods_; run;
Histamine Study Sum of Mean Source DF Squares Square F Value Pr > F Drug 1 5.993 5.993 2.71 0.1281 Depleted 1 15.448 15.448 6.98 0.0229 * Drug*Depleted 1 4.691 4.691 2.12 0.1734 Time 3 * * 24.03 0.0001 *** Time_Drug 3 * * 5.78 0.0175 * Time_Depleted 3 * * 21.31 0.0002 *** Time_Drug_Depleted 3 * * 12.48 0.0015 ** * - Test computed using Hotelling-Lawley trace
This example demonstrates how you can use ODS to provide links between different parts of your HTML procedure output.
Suppose that you are analyzing a 4 — 4 factorial experiment for an industrial process, testing for differences in the number of defective products manufactured by different machines using different sources of raw material. The data set Experiment is created as follows.
data Experiment; do Supplier = A,B,C,D; do Machine = 1 to 4; do rep = 1 to 5; input Defects @@; output; end; end; end; datalines; 2 6 3 3 6 8 6 6 4 4 4 2 4 0 4 5 5 7 8 5 13 12 12 11 12 16 15 14 14 13 11 10 12 12 10 13 13 14 15 12 2 6 3 6 6 6 4 4 6 6 0 3 2 0 2 4 6 7 6 4 20 19 18 21 22 22 24 23 20 20 17 19 18 16 17 23 20 20 22 21 ;
Suppose that you are interested in fitting a model to determine the effect that the sup-plier of raw material and machine type have on the number of defects in the products. If the F test for a factor is significant, you would like to follow up with a multiple comparisons procedure. Thus, the tables of interest are the model ANOVA and the multiple comparisons output.
The following statements demonstrate how you can link a row of the ANOVA table to the corresponding multiple comparisons table. This is done by altering the display of values (inserting links) in the Source column of the ANOVA table. The links are inserted by using the TEMPLATE procedure.
proc template; edit Stat.GLM.Tests; edit Source; translate _val_ = "Supplier" into ('<a href="#IDX6">' _val_ '</a>'), _val_ = "Machine" into ('<a href="#IDX8">' _val_ '</a>'); end; end; run;
In order to determine the value to use in the HTML anchor link (<A HREF="# ">), you can run the analysis once and view information on your output in the Results node of the SAS Explorer. The anchor name IDX6 is given to the table ANOVA.Means.Supplier.Defects.MCLines.Tukey.MCLines (the anchor name is automatically generated in the SAS run). The statements create the Supplier label as a link that, when clicked, opens the table of means from the Tukey s Studentized Range Test for Defects associated with the Supplier variable.
The IDX8 anchor name is given to the table ANOVA.Means.Machine.Defects.MCLines.Tukey.MCLines. The statements create the Machine label as a link that, when clicked, opens the table of means from the Tukey s Studentized Range Test for Defects associated with the Machine variable.
The following statements specify that ODS close the SAS listing destination and open the HTML destination. ODS writes the HTML output to the file anovab.htm .
ods listing close; ods html body='anovab.htm';
Since this is a balanced experiment, the ANOVA procedure computes the appropriate analysis, performed with the following statements:
proc anova data=Experiment; class Supplier Machine; model Defects = Supplier Machine; means Supplier Machine / tukey; quit; ods html close;
The output from the ANOVA procedure is displayed in Output 14.10.1.
The ANOVA procedure uses the Stat.GLM.Tests template to format the ANOVA table. The underlined text displayed in Output 14.10.1 shows the links in the table cells labeled as ˜Supplier and ˜Machine. Because of the modifications in the preceding statements, the Supplier table listing contains the HTML anchor reference to the tag IDX6. When you click on the ˜Supplier link, the appropriate multiple comparison table opens in your browser ( Output 14.10.2). The links corresponding to the Machine variable operate similarly.
The following example demonstrates how you can use ODS to create links between different types of analyses.
The data in the following example are selected from a larger experiment on the use of drugs in the treatment of leprosy (Snedecor and Cochran 1967, p. 422). Variables in the study are
drug | “ two antibiotics (˜a and ˜d) and a control (˜f) |
PreTreatment | “ a pretreatment score of leprosy bacilli |
PostTreatment | “ a posttreatment score of leprosy bacilli |
The data set is created as follows:
data drugtest; input drug $ PreTreatment PostTreatment @@; datalines; a 11 6 a 8 0 a 5 2 a 14 8 a 19 11 a 6 4 a 10 13 a 6 1 a 11 8 a 3 0 d 6 0 d 6 2 d 7 3 d 8 1 d 18 18 d 8 4 d 19 14 d 8 9 d 5 1 d 15 9 f 16 13 f 13 10 f 11 18 f 9 5 f 21 23 f 16 12 f 12 5 f 12 16 f 7 1 f 12 20 ;
The ODS HTML statement opens the HTML destination, specifies the body file name, requests that a table of contents be generated for the output, and specifies the file name of the frame to contain the body and table of contents. The NOGTITLE option in the ODS HTML statement specifies that titles are not to be included as an integral part of any generated graphics. For all graphics contained in the specified body file, titles appear in the body file and are external to graphics.
ods html body='glmb.htm' contents='glmc.htm' frame='glmf.htm' nogtitle; ods output LSMeans=lsmeans;
The ODS OUTPUT statement writes the table of LS-means to the data set called lsmeans .
The GLM procedure is invoked to perform an analysis of covariance and compute LS-means for the variable drug .
proc glm; class drug; model PostTreatment = drug PreTreatment / solution; lsmeans drug / stderr pdiff; quit;
The following steps demonstrate how you can create links to connect the results of different analyses. In this example, the table of LS-means is graphically summarized with the GCHART procedure. In the steps that follow, each part of the resulting chart is linked to a plot that displays the relationship between the PostTreatment response variable and the PreTreatment variable.
The following DATA step creates a new variable called drugclick that matches each drug value with an HTML file. The variable drugclick is used in the subsequent GCHART procedure run. The variable provides the connection information for linking the two parts of the analysis together. The files referred to in these statements are created in a later step.
data lsmeans; set lsmeans; if drug='a' then drugclick='href=drug1.htm'; if drug='d' then drugclick='href=drug2.htm'; if drug='f' then drugclick='href=drug3.htm'; run;
The following GOPTIONS and AXIS statements specify settings for the GCHART procedure. PROC GCHART is invoked, and the HBAR statement requests a horizontal bar chart for the variable drug . The length of the bars represent the value of the lsmean variable. The HTML option specifies the variable drugclick as the HTML linking variable to use. The FOOTNOTE1 and FOOTNOTE2 statements provide text that indicates how to use the links on the graph.
goptions ftext=swissb hsize=5.5in vsize=3.5in border cback=white; axis1 minor=none label=(angle=90 rotate=0); axis2 minor=none; title f=swiss 'Chart of LS-means for Drug Type'; proc gchart data=lsmeans; hbar drug / sumvar=lsmean type=mean frame cframe=ligr gaxis=axis1 raxis=axis2 html=drugclick; footnote1 j=l 'click on the bar to see a plot of PostTreatment'; footnote2 j=l 'versus PreTreatment for the corresponding drug'; format lsmean 6.3; run; footnote; ods html close; run;
The preceding statements create a chart that summarizes the information from PROC GLM and that contains links to a second graphic analysis (using the variable drugclick andtheHTMLoptioninPROCGCHART).
The following statements provide that second analysis. The three filesreferredtoby the drugclick variable are created as follows.
ods html body='drug1.htm' newfile=page; symbol1 c=white v=dot i=r; title 'Plot of PostTreatment versus PreTreatment'; proc gplot data=drugtest uniform; plot PostTreatment*PreTreatment / frame cframe=ligr; by drug notsorted; footnote; run; ods html close;
The NEWFILE option in the ODS HTML statement specifies that a new HTML file be created for each page of output. Note that page breaks occur only when a procedure explicitly starts a new page. The NEWFILE option also increments the filename for each new HTML file created, with the first filename corresponding to that given in the BODY= option, drug1.htm .
The GPLOT procedure is invoked, producing a plot of the variable PostTreatment versus the variable PreTreatment for each value of the drug variable. Thus, three plots are created, and each plot is contained in a separate HTML file. The files are named drug1.htm , drug2.htm , and drug3.htm . The filenames match those filenames specified as values of the drugclick variable.
The graphic in Output 14.11.2 displays the difference in lsmeans for each drug type. When you click on a bar that represents a value of the variable drug , the browser opens the plot of PostTreatment versus PostTreatment that corresponds to that value of the variable drug . Output 14.11.3 displays the plot corresponding to the drug type ˜f . You can view this graphic by clicking on the bottom bar in the bar chart in Output 14.11.2.