Presentation is loading. Please wait.

Presentation is loading. Please wait.

EPIB 698E Lecture 8 Raul Cruz-Cano Fall 2013. SAS ODS (Output Delivery System)

Similar presentations


Presentation on theme: "EPIB 698E Lecture 8 Raul Cruz-Cano Fall 2013. SAS ODS (Output Delivery System)"— Presentation transcript:

1 EPIB 698E Lecture 8 Raul Cruz-Cano Fall 2013

2 SAS ODS (Output Delivery System)

3 ODS is a powerful tool that can enhance the efficiency of statistical reporting and meet the needs of the investigator. To create output objects that can be send to destinations such as HTML, PDF, RTF (rich text format), or SAS data sets. To eliminate the need for macros that used to convert standard SAS output to a Microsoft Word, or HTML document Create graphs that enhance the output provided by certain procedures

4 Fish Measurement Data (reminder) ods graphics on; title 'Fish Measurement Data'; proc corr data=fish1 nomiss plots=matrix(histogram); var Height Width Length3 Weight3; run; ods graphics off; data Fish1 (drop=HtPct WidthPct); title 'Fish Measurement Data'; input Weight Length3 HtPct WidthPct @@; Weight3= Weight**(1/3); Height=HtPct*Length3/100; Width=WidthPct*Length3/100; datalines; 242.0 30.0 38.4 13.4 290.0 31.2 40.0 13.8 340.0 31.1 39.8 15.1 363.0 33.5 38.0 13.3 430.0 34.0 36.6 15.1 450.0 34.7 39.2 14.2 500.0 34.5 41.1 15.3 390.0 35.0 36.2 13.4 450.0 35.1 39.9 13.8 500.0 36.2 39.3 13.7 475.0 36.2 39.4 14.1 500.0 36.2 39.7 13.3 500.0 36.4 37.8 12.0. 37.3 37.3 13.6 600.0 37.2 40.2 13.9 600.0 37.2 41.5 15.0 700.0 38.3 38.8 13.8 700.0 38.5 38.8 13.5 610.0 38.6 40.5 13.3 650.0 38.7 37.4 14.8 575.0 39.5 38.3 14.1 685.0 39.2 40.8 13.7 620.0 39.7 39.1 13.3 680.0 40.6 38.1 15.1 700.0 40.5 40.1 13.8 725.0 40.9 40.0 14.8 720.0 40.6 40.3 15.0 714.0 41.5 39.8 14.1 850.0 41.6 40.6 14.9 1000.0 42.6 44.5 15.5 920.0 44.1 40.9 14.3 955.0 44.0 41.1 14.3 925.0 45.3 41.4 14.9 975.0 45.9 40.6 14.7 950.0 46.5 37.9 13.7 ; run; The data set contains 35 fish from the species Bream caught in Finland's lake Laengelmavesi with the following measurements: Weight (in grams) Length3 (length from the nose to the end of its tail, in cm) HtPct (max height, as percentage of Length3) WidthPct (max width, as percentage of Length3)

5 Creating Excel Report There are several options: –PROC EXPORT : It’s the same as the point and click method but you can do it with code. –LIBNAME ENGINE LIBNAME engine is one of the newest methods to transfer information from SAS into Excel. Lets you use Excel as a SAS library. LIBNAME engine allows advanced customization of your output. It does not give full control of Excel Excel does not need to be installed on the machine running SAS. –EXCELXP TAGSET : ExcelXP tagset is an ODS (Output Delivery System) destination available in SAS version 9.1 that utilizes the Extensible Markup Language (XML). It can be downloaded from the SAS website. Using the ExcelXP Tagset is a powerful method to control formatting of a spreadsheet. ExcelXP tagset can be used to export the results of PROC REPORT, PROC TABULATE, or PROC PRINT. It can display multiple tables per worksheet as well as multiple worksheets.

6 ODS RTF Output (rich text file) ods rtf file='C:\freq.rtf'; proc freq data=blood; Table GENDER; RUN; ods rtf close; Rft file data blood; INFILE 'C:\blood.txt'; INPUT subjectID $ gender $ bloodtype $ age_group $ RBC WBC cholesterol; run;

7 ODS RTF Output (rich text file) ods rtf file='C:\freq.rtf '; proc freq data=blood; Table GENDER; RUN; ods rtf close; directory File name

8 Creating Excel Report DATA style; INFILE ‘C:\style.txt'; INPUT Name $ 1-21 style $ 23-40 Origin $ 42; RUN; ods tagsets.excelxp file="C:\comparision.xls" style =statistical options( sheet_interval= 'none' suppress_bylines= 'n’ ); PROC PRINT DATA = style; WHERE style = 'Impressionism'; TITLE 'Major Impressionist Painters'; FOOTNOTE 'F = France N = Netherlands U = US'; RUN; ods tagsets.excelxp close ;

9 (2) Or send to output file, then use PROC PRINT proc means data = blood; var RBC WBC cholesterol; output out = results; run; data results; set results (keep = _STAT_ RBC WBC cholesterol); if _STAT_ = "STD" then delete; run; ods tagsets.excelxp file = 'C:\Users\sphcart\Documents\EPIB698E\print_test.xls'; proc print data = results; title 'blood results'; footnote; run; ods tagsets.excelxp close; (1) Try the PROC anyway ods tagsets.excelxp file = 'C:\Users\sphcart\Documents\EPIB698E\results_proc_mean.xls‘ style=statistical; options( sheet_interval='none' suppress_bylines='n'); proc freq data=Color; tables Eyes Hair Eyes*Hair / out=FreqCount; weight Count; title 'Eye and Hair Color of European Children'; run; ods tagsets.excelxp close ; Creating Excel Report for PROC that by default can’t be used in the ODS (2) Might require a little research (not all PROCs use the same way to send to their output to a datatset)… title 'Correlations for a Fitness and Exercise Study'; proc corr data=Fitness nomiss outp=CorrOutp; var weight oxygen runtime; run; title 'Output Data Set from PROC CORR'; proc print data=CorrOutp noobs; run;

10 Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

11 Proc GCHART for bar charts Example: A bar chart showing the distribution of blood types from the Blood data set DATA blood; INFILE ‘C:\blood.txt'; INPUT ID Sex $ BloodType $ AgeGroup $ RBC WBC chol; run; title "Distribution of Blood Types"; proc gchart data=blood; vbar BloodType; run;

12 Proc GCHART for bar charts VBAR: request a vertical bar chart for the variable Alternatives to VBAR are as follows: HBAR: horizontal bar chart VBAR3D: three-dimensional vertical bar chart HBAR3D: three-dimensional horizontal bar chart PIE: pie chart PIE3D: three-dimensional pie chart DONUT: donut chart

13 A Few Options proc gchart data=blood; vbar bloodtype/space=0 type=percent ; run; Controls spacing between bars Changes the statistic from frequency to percent

14 Type option Type =freq : displays frequencies of a categorical variable Type =pct (Percent): displays percent of a categorical variable Type =cfreq : displays cumulative frequencies of a categorical variable Type =cpct (cPercent): displays cumulative percent of a categorical variable

15 Basic Output This value of 7,000 corresponds to a class ranging from 6500 to 7500 (with a frequency of about 350) SAS computes midpoints of each bar automatically. You can change it by supplying your own midpoints: vbar RBC / midpoints=4000 to 11000 by 1000;

16 Creating charts with values representing categories SAS places continuous variables into groups before generating a frequency bar chart If you want to treat the values as discrete categories, you can use DISCRETE option Example: create bar chart showing the frequencies by day of the week for the visit to a hospital

17 libname d “C:\”; data day_of_week; set d.hosp; Day = weekday(AdmitDate); run; *Program Demonstrating the DISCRETE option of PROC GCHART; title "Visits by Month of the Year"; proc gchart data=day_of_week; vbar Day / discrete; run;

18 The Discrete Option proc gchart data= day_of_week; vbar day /discrete; run; quit; Discrete establishes each distinct value of the midpoint variable as a midpoint on the graph. If the variable is formatted, the formatted values are used for the construction. If you use discrete with a numeric variable you should: 1. Be sure it has only a few distinct values. or 2. Use a format to make categories for it.

19 GPLOT The GPLOT procedure plots the values of two or more variables on a set of coordinate axes (X and Y). The procedure produces a variety of two- dimensional graphs including –simple scatter plots –overlay plots in which multiple sets of data points display on one set of axes

20 Procedure Syntax: PROC GPLOT PROC GPLOT; PLOT y*x ; run; Example: plot of systolic blood pressure (SBP) by diastolic blood pressure (DBP) title "Scatter Plot of SBP by DBP"; proc gplot data=d.clinic; plot SBP * DBP; run;

21 *controlling the axis ranges; title "Scatter Plot of SBP by DBP"; proc gplot data=d.clinic; plot SBP * DBP / haxis=70 to 120 by 5 vaxis=100 to 220 by 10; Run;

22 Multiple plots can be made in 3 ways: (1)proc gplot; plot y1*x y2*x /overlay; run; plots y1 versus x and y2 versus x using the same horizontal and vertical axes. (2) proc gplot; plot y1*x; plot2 y2*x; run; plots y1 versus x and y2 versus x using different vertical axes. The second vertical axes appears on the right hand side of the graph. (3) proc gplot ; plot y1*x=z; run; uses z as a classification variable and will produce a single graph plotting y1 against x for each value of the variable z.

23 Using the AXIS Statement AXIS statements can be defined anywhere in your SAS program. They are global and remain in effect until redefined, canceled, or until the end of your SAS session. AXIS statements are not applied automatically, and must be explicitly assigned by an option in the procedure that uses them. Proc GCHART RAXIS= /* response axis */ MAXIS= /* midpoint axis */ GPLOT HAXIS= /*horizontal axis*/ VAXIS= /* vertical axis */

24 *controlling the axis ranges; title "Scatter Plot of SBP by DBP"; proc gplot data=d.clinic; plot SBP * DBP / haxis=70 to 120 by 5 vaxis=100 to 220 by 10; run;

25 axis1 order=('North' 'South' 'East' 'West') label=('region of the country') length=30; axis2 label=('sum of the total sales') length=30; proc gchart data=d.sales; vbar Region / sumvar=TotalSales type=sum maxis=axis1 raxis=axis2; format TotalSales dollar8.; Run; sumvar= summary variable


Download ppt "EPIB 698E Lecture 8 Raul Cruz-Cano Fall 2013. SAS ODS (Output Delivery System)"

Similar presentations


Ads by Google