*************************************************************; * Name: UCLA_ODS_Presentation ; * SAS ODS Technology for ; * Todays Decision Makers ; * ; * Function: Produce ODS Examples ; * ; * Programmer: Sunil Gupta, Gupta Programming ; * Sunil@GuptaProgramming.com ; * (805) 584-6182 ; * www.GuptaProgramming.com ; * Copyright(C) 2003 ; * ; * Author - Quick Results with the Output Delivery System; * ; * SAS Version: 8.2 ; * ; * Date: August 29, 2003 ; * Verification Date: August 30, 2003 ; * ; * Input data sets: demog ; * Output file: html, pdf, rtf ; * ; * Revision Log ; *************************************************************; * DATE PROGRAMMER CHANGE ; *------------------------------------------------------------; *------------------------------------------------------------; libname ucla 'c:\'; dm output 'clear'; dm log 'clear'; proc format; value gendfmt 0=' Man' 1=' Woman'; value racefmt 0=' Nonwhite' 1=' White'; picture pctpct low-high = '99%' (prefix=' ('); value meanfmt low - 99 = 'white' 100 - high = 'red'; quit; ***********************; * Create demog data set; ***********************; data demog; input patient $3. gender 3. height 4.1 weight 4. age 5.1 race 3. drug $7.; format height age 4.1 gender gendfmt. race racefmt.; label patient='Patient' gender='Sex' height='Height' weight='Weight' age='Age' race='Race' drug='Drug'; cards; 001 1 74.4 257 67.9 1 Active 002 1 63.1 168 36.7 0 Active 003 1 69.6 264 74.6 0 Placebo 004 1 63.2 270 73.8 1 Placebo 005 1 67.8 209 57.8 1 Active 006 0 56.7 116 47.5 1 Active 007 1 70.4 150 47.8 1 Active 008 1 68.5 172 82.6 1 Active 009 0 66.4 212 25.1 0 Active 010 1 68.1 216 60.6 1 Placebo 011 1 62.8 193 80.0 1 Active 012 1 73.6 198 77.4 1 Active 013 0 59.8 117 72.3 1 Active 014 0 74.7 179 37.4 0 Placebo 015 1 73.0 195 21.4 1 Active 016 1 57.7 213 27.3 1 Active 017 1 59.9 199 43.1 1 Active 018 1 70.2 219 67.3 0 Active 019 1 68.6 236 62.2 1 Placebo 020 1 70.7 255 66.4 1 Active 021 1 71.6 228 27.3 1 Active 022 1 58.9 111 68.3 1 Active 023 1 65.7 194 67.1 0 Active 024 1 63.2 234 65.2 0 Active 025 1 72.4 162 56.1 0 Placebo ; run; *proc contents; run; ***********************; * Create demog data set; ***********************; ODS HTML FILE = 'c:\demog_style_barretsblue.htm' STYLE = barrettsblue; PROC UNIVARIATE DATA=DEMOG; VAR WEIGHT; RUN; ODS HTML CLOSE; * brick style; ODS HTML FILE = 'c:\demog_style_brick.htm' STYLE = brick; PROC UNIVARIATE DATA=DEMOG; VAR WEIGHT; RUN; ODS HTML CLOSE; ODS pdf FILE = 'c:\demog_style_brick.pdf' STYLE = brick; PROC UNIVARIATE DATA=DEMOG; VAR WEIGHT; RUN; ODS pdf CLOSE; ODS rtf FILE = 'c:\demog_style_brick.rtf' STYLE = brick; PROC UNIVARIATE DATA=DEMOG; VAR WEIGHT; RUN; ODS rtf CLOSE; ***********************; * Create Excel file; ***********************; ODS HTML FILE = 'c:\demog.xls' style = minimal; PROC UNIVARIATE DATA=DEMOG; VAR WEIGHT; RUN; ODS HTML CLOSE; ***********************; * Example of proc document; ***********************; * Save results as document file type; ods document name = ucla.myresults2 (update); ods rtf file = 'c:\rtffile2.rtf'; proc freq data=demog; tables gender; run; ods rtf close; ods document close; * access document file for another destination; ods pdf file = 'c:\pdffile2.pdf' style=barrettsblue; proc document name = ucla.myresults2 (update); replay; run; ods pdf close; ods document close; ***********************; * Example of proclabel; ***********************; ods html body = 'c:\htmlbfile.htm' contents = 'c:\htmltocfile.htm' frame = 'c:\htmlffile.htm'; ODS ProcLabel 'This is my FREQ label'; Proc Freq data=demog; tables gender; run; ODS html CLOSE; ***********************; * Example selecting objects with by statement; ***********************; PROC SORT DATA=DEMOG; BY DRUG; RUN; ODS HTML FILE='c:\select_weight_demog.htm'; ODS HTML SELECT UNIVARIATE.BYGROUP1.WEIGHT.BASICMEASURES UNIVARIATE.BYGROUP2.WEIGHT.BASICMEASURES; PROC UNIVARIATE DATA=DEMOG; BY DRUG; VAR WEIGHT; RUN; ODS HTML CLOSE; ***********************; * Example selecting objects with multiple variables; ***********************; ODS HTML FILE= 'c:\select_weight_height_demog.htm'; ODS HTML SELECT UNIVARIATE.WEIGHT.BASICMEASURES UNIVARIATE.HEIGHT.BASICMEASURES; PROC UNIVARIATE DATA=DEMOG; VAR WEIGHT HEIGHT; RUN; ODS HTML CLOSE; ***********************; * Example of output data set; ***********************; ODS OUTPUT BASICMEASURES = MEASURE; PROC UNIVARIATE DATA=DEMOG; VAR WEIGHT; RUN; ODS OUTPUT CLOSE; ***********************; * Example of match all; ***********************; ODS OUTPUT BASICMEASURES /* object name */ (MATCH_ALL = MEASURE_DSN /* macro name */ PERSIST = PROC) /* maintain selection list */ = MEASURE; /* data set names - measure, measure1, measure2 */ PROC UNIVARIATE DATA=DEMOG; VAR WEIGHT HEIGHT; RUN; PROC UNIVARIATE DATA=DEMOG; VAR AGE;RUN; ODS OUTPUT CLOSE; %put &measure_dsn; proc contents data=measure; run; proc print data=measure; var varvalue; where locmeasure = 'Mean'; run; data allmeans; set &measure_dsn; * set measure measure1 measure2; where locmeasure = 'Mean'; keep varname locmeasure locvalue; run; proc print data=allmeans; run; * code not used; data allmeans2; merge measure (rename =(locvalue = wgt)) measure1 (rename =(locvalue = hgt)) measure2 (rename =(locvalue = age)) ; where locmeasure = 'Mean'; keep _proc_ locmeasure wgt hgt age; run; proc print data=allmeans2; run; ***********************; * Example of traffic lightling; ***********************; proc format; value traffic low - 99 = 'cx006600' /* green */ 100 - high = 'cxFF9900'; /* orange */ quit; ods html file = 'c:\print_results.htm'; proc report data=allmeans noheader nowd; columns varname locvalue; define locvalue /style = {background = traffic.}; run; ods html close; ***********************; * Example of plots; ***********************; ods rtf file = 'c:\plots.rtf'; proc univariate data = demog plots; var weight; run; ods rtf close; ***********************; * Example of rtf control words; ***********************; ods escapechar = '^'; data rtfcontrol; a = "The text uses RTF control words " || '^R"\i italic text \i0 "' || ' regular text ' || '^R"\ul underlined text \ul0 "' || '^R"\strike strike text. \strike0 "'; run; ods rtf file = 'c:\rtf_control.rft'; title1 '^R/RTF"\ul " Title contains underlined text'; proc print data=rtfcontrol; run; ods rtf close; * example of page x of y - version 8.2; *title j=l font=arial bold "G-8905 Study - Patient Listing of Hemotology Data" j=r font=arial bold "{Page} {\field{\*\fldinst{ PAGE }}} \~{of}\~{\field{\*\fldinst { NUMPAGES }}}"; ods rtf file = 'c:\pagexofy.rft'; title 'This document will have page x of y ' j=r 'Page ^{pageof}'; proc print data=demog; var gender height weight; run; ods rtf close; ***********************; * Examples of Proc tabulate, report and print; ***********************; options orientation=portrait nodate nonumber center mprint mlogic symbolgen; ods escapechar = '^'; * Use minimal style; ods rtf file='c:\baseline_tables.rtf' style=minimal; * note bodytitle not working in version 8.2; * bodytitle ; title font=arial bold "Table 1. Baseline Characteristics: Sex, Race^{super a}" " Page ^{pageof}"; footnote1 "^S={font_face=arial} ^{super a}Race: Nonwhite consists of black, Hispanic, and Native American^S={} "; footnote2 "^S={font_face=arial font_style=italic}Program: /stat/druga/program1.sas ^S={}" ; footnote3 "^S={font_face=arial font_style=italic}Output: Baseline_tables.rtf (Date Generated: &sysdate) ^S={}" ; * PROC TABULATE EXAMPLE; %let mystyle = %str(font_face="arial" font_weight=bold); proc tabulate data=demog missing formchar=' -----------' style=[font_face="courier"]; /* Style for all data */ /* styles for column and row header */ class gender race drug / style=[&mystyle]; classlev gender race drug / style=[&mystyle]; keyword n pctn / style=[&mystyle]; /* style for box label */ table (gender race), drug=' '* (n='N'*f=7. pctn=' %' *f=pctpct. ) / box=[label='Baseline ' style=[&mystyle]] rts=43; run; * table 2; ***********************; title font=arial bold "Table 2. Baseline Characteristics: Age, Height, Weight - Example of subscript^{sub a}" " Page ^{pageof}"; footnote1 "^S={font_face=arial} ^{sub a}Weight units are in lbs. ^S={}" ; footnote2 "^S={font_face=arial font_style=italic}Program: /stat/druga/program1.sas ^S={}" ; footnote3 "^S={font_face=arial font_style=italic}Output: Baseline_tables.rtf (Date Generated: &sysdate) ^S={}" ; proc tabulate data=demog missing formchar=' -----------' style=[font_face="courier"]; /* Style for all data */ /* styles for column and row header */ class drug / style=[font_face="arial" font_weight=bold]; classlev drug / style=[font_face="arial" font_weight=bold]; var age height weight /style=[font_face="times" font_weight=bold]; keyword n mean min std max/ style=[font_face="arial" font_weight=bold]; /* style for box label */ table age = 'Age'*(n='N'*f=15. mean='Mean'*f=15.1 std='STD'*f=4.2 min='Min'*f=4.1 max='Max'*f=4.1) height = 'Height'*(n='N'*f=15. mean='Mean'*f=15.1 std='STD'*f=4.2 min='Min'*f=4.1 max='Max'*f=4.1) weight = 'Weight'*(n='N'*f=15. mean='Mean'*f=15.1 std='STD'*f=4.2 min='Min'*f=4.1 max='Max'*f=4.1) , drug=' ' / box=[label='Baseline ' style=[font_face="arial" font_weight=bold]] rts=53; run; * PROC PRINT EXAMPLE; ***********************; title font=arial bold "Table 3. Sample Proc Print" " Page ^{pageof}"; footnote1; footnote2 "^S={font_face=arial font_style=italic}Program: /stat/druga/program1.sas ^S={}" ; footnote3 "^S={font_face=arial font_style=italic}Output: Baseline_tables.rtf (Date Generated: &sysdate) ^S={}" ; proc print data=demog (obs=5) noobs style(header) = [font_face="arial" font_weight=bold] /* Style for headers */ style(data)= [font_face="arial"]; /* Style for all data */ var patient drug gender race age height weight; run; ods rtf close; ***********************; * Example of proc report; ***********************; ods rtf file='c:\report_tables.rtf' style=minimal; * note bodytitle not working in version 8.2; * bodytitle ; proc report data=demog nowd style(header column) = [font_face="arial"]; column patient drug gender race age height weight; define patient/ style(header column)=[font_face = times font_weight=bold]; run; ods rtf close;