/* The Output Delivery System (ODS) organizes SAS output into one or more tables. Table definitions within each procedure tell ODS how to display the raw procedure output. Style definitions specify background colors, table borders, fonts, spacing, etc. of the table. Output destinations specify what type of file ODS will create. These destinations can be HTML, RTF, PDF, LaTex, and several other types. In these examples, HTML, RTF, and PDF files will be created. First, let's read in some data on which we will run various SAS procedures and create different ODS destinations. */ options ls=90; filename foo url "http://www.uvm.edu/~abh/stat295/datasets/pledges.dat"; data pledges; infile foo; input id sex $ agegroup pledged miles; label pledged = "Amount pledged" miles = "Miles walked"; run; /* Let's get some descriptive statistics for each sex and see if there is a difference between males and females in the amount of money pledged and in the number of miles walked. Let's also do a two-way ANOVA with sex and agegroup. */ proc univariate data=pledges normal; class sex; var pledged miles; qqplot pledged miles / cframe=GRAYEE; title "Descriptive statistics for amount pledged and miles walked"; run; proc ttest data=pledges; class sex; var pledged miles; title "Compare pledges and miles walked between sexes"; run; proc glm data=pledges; class sex agegroup; model pledged miles = sex|agegroup; lsmeans sex|agegroup / stderr; title "Two-way ANOVA with sex and agegroup"; run; quit; /* As usual, the results appear in the output window. Formatting is done by putting the right number of spaces between columns of numbers. This aligns columns correctly only because the output window uses a non-proportional font. The contents of the output window can be saved to a .lst file. This file is a plain text file and when opened in a word processor like Microsoft Word, the results are often misaligned and difficult to read because the font in Word may be a proportional font, like Times Roman or Arial instead of a non-proportional font like Courier. With ODS, we can turn off the default text listing and make the output go into an RTF file, which can then be opened in Word. */ ODS listing close; ODS RTF file="ODS_output.rtf"; proc univariate data=pledges normal; class sex; var pledged miles; qqplot pledged miles / cframe=GRAYEE; title "Descriptive statistics for amount pledged and miles walked"; run; proc ttest data=pledges; class sex; var pledged miles; title "Compare pledges and miles walked between sexes"; run; proc glm data=pledges; class sex agegroup; model pledged miles = sex|agegroup; lsmeans sex|agegroup / stderr; title "Two-way ANOVA with sex and agegroup"; run; quit; ODS RTF close; /* Alternatively, we can create a PDF file that can be opened by Adobe Reader. */ ODS PDF file="ODS_output.pdf"; proc univariate data=pledges normal; class sex; var pledged miles; qqplot pledged miles / cframe=GRAYEE; title "Descriptive statistics for amount pledged and miles walked"; run; proc ttest data=pledges; class sex; var pledged miles; title "Compare pledges and miles walked between sexes"; run; proc glm data=pledges; class sex agegroup; model pledged miles = sex|agegroup; lsmeans sex|agegroup / stderr; title "Two-way ANOVA with sex and agegroup"; run; quit; ODS PDF close; /* Alternatively, we can create an HTML file that can be opened by a web browser. */ ODS HTML body="ODS_output.html"; proc univariate data=pledges normal; class sex; var pledged miles; qqplot pledged miles / cframe=GRAYEE; title "Descriptive statistics for amount pledged and miles walked"; run; proc ttest data=pledges; class sex; var pledged miles; title "Compare pledges and miles walked between sexes"; run; proc glm data=pledges; class sex agegroup; model pledged miles = sex|agegroup; lsmeans sex|agegroup / stderr; title "Two-way ANOVA with sex and agegroup"; run; quit; ODS HTML close; /* There are a lot of options available to you when sending SAS output to an HTML destination. In the previous example, the entire output was sent to the body of the HTML file. We can also create a table of contents with frames by adding these options to the ODS command. We also have a lot of control regarding various titles, both in the body and frame. By adding to the ODS command from above, we can create linked HTML files for our SAS output. When using these kinds of options, the frame file is the one that should be opened in a web browser, since it contains the body and contents links. */ ODS HTML body="ODS_body.html" contents="ODS_contents.html" frame="ODS_frame.html"; proc univariate data=pledges normal; class sex; var pledged miles; qqplot pledged miles / cframe=GRAYEE; title "Descriptive statistics for amount pledged and miles walked"; run; proc ttest data=pledges; class sex; var pledged miles; title "Compare pledges and miles walked between sexes"; run; proc glm data=pledges; class sex agegroup; model pledged miles = sex|agegroup; lsmeans sex|agegroup / stderr; title "Two-way ANOVA with sex and agegroup"; run; quit; ODS HTML close; /* Beginning with version 9.1, SAS introduced ODS Graphics, an experimental extension of the Output Delivery System that automatically adds statistical graphics output to certain statistical procedures simply by turning the option on. The type of graphic output that is produced depends on the statistical procedure being run. According to the documentation, ODS graphics for GLM will give boxplots in a one-way ANOVA, so we will modify the GLM model statement to get a one-way ANOVA for agegroup. Let's rerun the above example with ODS graphics turned on and see what we get. Sometimes we may get nothing, because ODS graphics is a Java application that is sensitive to the version and configuration of Java that is installed on your computer. Let's also change the HTML style from the default to one called "Brick". Other HTML styles can be found be going to the "Tools" menu, clicking on "Options", then on "Preferences". In this tabbed window, click on the "Results" tab and then on the "Style" pull-down menu. */ ODS HTML body="ODS_body.html" STYLE=Brick contents="ODS_contents.html" frame="ODS_frame.html" (TITLE="ODS HTML Example with ODS Graphics"); ODS graphics on; proc univariate data=pledges normal; class sex; var pledged miles; qqplot pledged miles / cframe=GRAYEE; title "Descriptive statistics for amount pledged and miles walked"; run; proc ttest data=pledges; class sex; var pledged miles; title "Compare pledges and miles walked between sexes"; run; proc glm data=pledges; class agegroup; model pledged miles = agegroup; lsmeans agegroup / stderr; title "One-way ANOVA with agegroup"; run; quit; ODS graphics off; ODS HTML close; /* ODS tables can also be saved into SAS data sets. In order to find out what the tables created by PROC GLM are called, we can use the TRACE function. Information about each table created by the procedure is written to the log window. */ ODS TRACE on; proc glm data=pledges; class agegroup; model pledged miles = agegroup; lsmeans agegroup / stderr; title "One-way ANOVA with agegroup"; run; quit; ODS TRACE off; /* Once we know the name(s) of the table we want, we can use an ODS OUTPUT statement to save it to a SAS data set. */ ODS OUTPUT LSMeans = ODSmeanstable; proc glm data=pledges; class agegroup; model pledged miles = agegroup; lsmeans agegroup / stderr; title "One-way ANOVA with agegroup"; run; quit; ODS OUTPUT close;