C H A P T E R 1 Writing Rports with SAS Prsnting information in a way that s undrstood by th audinc is fundamntally important to anyon s job. Onc you collct your data and undrstand its structur, you nd to b abl to rport and summariz your findings ffctivly and fficintly. With SAS procdurs, SAS DATA stps, and SAS faturs such as th Output Dlivry Systm (ODS) and th macro facility, you hav th tools to succd at writing programs that analyz your data and crat rports. Using This Book This book prsnts xampls of SAS programs that solv many common rportwriting tasks. Th xampls rang from simply listing th obsrvations in a data st to computing summary statistics to crating customizd rports with SAS DATA stp statmnts to tailoring rport output by including ODS faturs. Each chaptr in this book groups rports of a similar typ as dscribd in Tabl 1.1. Tabl 1.1 List of Chaptr Topics Chaptr Topic Dscription 2 Dtail Rports List obsrvations. 3 Summary Rports Summariz obsrvations. 4 Customizd Rports Us SAS programming statmnts to customiz th prsntation of data. 5 Multipanl Rports Plac multipl rows of information sid-by-sid. 6 Enhancing Rports with ODS Faturs Apply ODS faturs to nhanc th formatting of rports. Each xampl includs th following information in this ordr: a brif statmnt of th goal of th xampl th rport output a tabl that lists th SAS cod faturs found in th xampl a dscription of th procss to solv th rport-writing task and a dscription of th data st that th xampl uss th SAS program that crats th output with annotations of th cod in th lft margin othr ways of solving th sam rport-writing task (optional) mor dtaild discussions of th spcial faturs of th xampl (optional) Th xampl data sts analyzd in this book wr dvisd to b structurally simpl so that th focus of ach xampl is th rport-writing tool rathr than th uniqu charactristics of th data st. S Appndix A, Crating th Exampl Data Sts, for dtails on th contnts of ach xampl data st.
2 SAS uid to Rport Writing: Exampls As you rad ach xampl, kp in mind how you can adapt th cod to rport rsults from your data sts. You can accss th data sts and programs prsntd in this book from th companion Wb sit for this book: support.sas.com/companionsits. Undrstanding SAS Rport-Writing Tools Most SAS procdurs produc output in a standard format. Two procdurs, REPORT and TABULATE, allow som customization of output layout. DATA stps and ODS faturs provid th most flxibility in customizing and slcting rport output. Th xampls in this book focus on th application of rportwriting procdurs, DATA stps, and ODS in producing rports. Whn writing a program to crat a rport, you nd to know which SAS procdurs spcializ in th kind of rport you want to produc. Rports can b catgorizd as dtail, summary, customizd, and multipanl. Exampls of ach ar shown in Figurs 1.1 through 1.4. Dtail rports list information at th obsrvation lvl of a data st (s Figur 1.1). Summary rports summariz obsrvations and produc output such as frquncy counts and dscriptiv statistics (s Figur 1.2). Customizd rports list information in a styl that is diffrnt than th standard output from a SAS procdur. Oftn ths ar producd with DATA stp programming (s Figur 1.3). Multipanl rports prsnt multipl rows of information sid-by-sid (s Figur 1.4). Som ovrlap dos xist btwn th catgoris. For xampl, a dtail rport may includ summaris, and a multipanl rport may contain dtail and summary information. Figur 1.1 Exampl of a Dtail Rport Study Hights and Wights ID ROUP ENDER HT WT AE 1 301 B F 64 110 32 2 302 A M 71 142 42 3 303 A M 72 206 34 4 304 B M 69 160 43 5 305 A F 65 138 32 6 306 A F 65 196 32 7 307 B M 70 242 40.. mor rows.
Chaptr 1 Writing Rports with SAS 3 Figur 1.2 Exampl of a Summary Rport Study Hights and Wights Hight(in) Wight(lb) Ag at Exam roup A B Man Std Man Std Man Std ndr Fmals 64.6 1.6 144 21.6 35.4 7.5 Mals 69.5 2.6 169 24.9 35.9 9.0 Fmals 65.9 2.6 139 21.4 36.2 7.3 Mals 69.5 2.7 169 20.0 36.6 8.5 Figur 1.3 Exampl of a Customizd Rport Study Hights and Wights roup A Mals Man Wight: 169 Man Hight: 69.5 roup B Mals Man Wight: 169 Man Hight: 69.5 TTst Rsults: Mals roup A vs roup B Wight: No significant diffrnc (p>0.05) TTst Rsults: Mals roup A vs roup B Hight: No significant diffrnc (p>0.05) roup A Fmals Man Wight: 144 Man Hight: 64.6 roup B Fmals Man Wight: 139 Man Hight: 65.9 TTst Rsults: Fmals roup A vs roup B Wight: No significant diffrnc (p>0.05) TTst Rsults: Fmals roup A vs roup B Hight: Significant diffrnc (p < 0.05) Figur 1.4 Exampl of a Multipanl Rport Study Hights and Wights r o u p ID n d r Ht Wt Ag r o u p ID n d r Ht Wt Ag r o u p ID n d r Ht Wt Ag B 301 F 64 110 31 B 339 F 65 143 34 A 377 F 66 152 33 A 302 M 71 142 42 B 340 M 68 181 26 B 378 M 69 176 53 A 303 M 72 206 34 A 341 M 66 168 44 B 379 F 64 127 41 B 304 M 69 160 43 B 342 M 70 171 44 B 380 M 66 174 52 A 305 F 64 138 32 B 343 M 68 168 31 B 381 M 69 154 39 A 306 F 65 196 32 B 344 M 71 162 24 B 382 F 66 135 41 mor rows.
4 SAS uid to Rport Writing: Exampls Tabl 1.2 prsnts an ovrviw of ach catgory of rport and th SAS procdurs bst suitd to produc rports of that typ. Tabl 1.2 Rport Typs and th Procdurs Usd to Produc th Diffrnt Typs Rport Typ Procdur/Stp Dscription Dtail PRINT Producs data listings quickly; can supply titls, footnots, and column sums. REPORT Offrs mor control and customization than PROC PRINT; can produc both column and row sums; has DATA stp computation abilitis. SQL Combins Structurd Qury Languag and SAS faturs such as formats; can manipulat data and crat a SAS data st in th sam stp that crats th rport; can produc column and row statistics; dos not offr as much control ovr output as PROC PRINT and PROC REPORT. MEANS, SUMMARY, UNIVARIATE Computs dscriptiv statistics for numric variabls; can produc a printd rport and crat an output data st. Summary PRINT Producs only on summary rport; can sum th BY variabls. REPORT Combins faturs of th PRINT, MEANS, and TABULATE procdurs with faturs of th DATA stp in a singl rportwriting tool; can also crat an output data st. SQL Computs dscriptiv statistics for on or mor SAS data sts or DBMS tabls; can produc a printd rport or crat a SAS data st. TABULATE Producs dscriptiv statistics in a tabular format; can produc multidimnsional tabls with dscriptiv statistics; can also crat an output data st. Customizd DATA Stp Producs highly customizd rports of all typs using SAS programming statmnts. Multipanl All procdurs whn snding output to a nonlisting dstination; REPORT whn snding output to ithr th LISTIN or a nonlisting dstination Producs sid-by-sid rports. Most xampls in this book us PROC REPORT and PROC TABULATE. A fw xampls us PROC PRINT and a fw xampls us DATA stps. On xampl uss PROC MEANS and anothr uss PROC FREQ. PROC FORMAT is usd throughout to add labls and othr information to th rports. Intgrating ODS and Rport Writing ODS is an intgral part of th rport-writing procss. It can b usd in all catgoris of rports to dsign th layout of a rport, improv th look of a rport, and slct th contnts of a rport. Th dfault dstination of your output whn you start your SAS sssion is LISTIN. Th LISTIN dstination is th traditional monospac SAS output. Th xampls in Chaptrs 2, 3, 4, and 5 ar writtn to snd output to th LISTIN dstination. Svral of ths xampls ar modifid in Chaptr 6 to snd output to nonlisting dstinations such as RTF and HTML.
Chaptr 1 Writing Rports with SAS 5 Associating Typs of Rports and th Exampls in This Book Appndix B, Cross-Rfrnc of th Exampls in This Book, prsnts a crossrfrnc of th xampls in this book to th typ of rport, procdurs usd, data sts usd, and ODS nhancd vrsions of th xampls. Th rows of Tabl B.1 in Appndix B list th xampls prsntd in Chaptrs 2 through 5. A tabl in th introduction to ach of th Chaptrs 2 through 5 rpats th prtinnt rows from Tabl B.1. Th xampls in Chaptr 6 ar drivd from th xampls in Chaptrs 2 through 5, and a tabl linking th xampls in Chaptr 6 to th original vrsions is prsntd in th introduction to Chaptr 6 and rpatd in Tabl B.2 in Appndix B. Using PROC SQL as a Rport-Writing Tool PROC SQL can also produc rports, but non of th xampls in this book apply this procdur to a rport-writing task. PROC SQL is a multipurpos procdur that is th SAS implmntation of Structurd Qury Languag. You can produc dtail rports with PROC SQL, but th rport formatting options in th procdur ar limitd. In th procss of crating your rport, you may find PROC SQL most usful in combining your data sts and obtaining intrmdiat rsults that ar includd in your final rports. For mor information on PROC SQL, s Th SQL Procdur in th Procdurs sction of Bas SAS 9.1 Procdurs uid. Displaying Rsults raphically Th xampls in this book concntrat on producing txt-basd tabls. Som imags ar includd in th txt rports in Chaptr 6, and on xampl in Chaptr 6 includs a programmatically drivd graphical rport. A pictur can b invaluabl in convying rsults. Whn you combin both picturs and txt in a rport, you can hlp your audinc bttr undrstand your rsults. Whil plotting data is byond th scop of this book, do not ignor this topic. Th bst rfrnc for prsnting data graphically is SAS/RAPH 9.1 Rfrnc. To gt startd in producing graphical rports, look for SAS Prss titls and SUI confrnc procdings, as dscribd in th Rfrncs sction of this chaptr. Ths rsourcs will hlp you combin graphs with th matrial you v larnd in this book.
6 SAS uid to Rport Writing: Exampls Writing a Rport Program in Fiv Stps Writing a rport can b an itrativ procss. You will likly find that it taks svral tris to produc th rport you nd. Bfor starting your rport program, mak sur you undrstand your data and th typs of information that th rport should convy. Do not concntrat on th styl attributs of th rport until you r sur you can produc th basic output. Thn aftr succssfully stablishing th structur of th rport, add th formatting faturs that improv th look and radability of your rport. Ths fiv stps can guid you in writing your rport programs. 1. Stat th information that th rport should convy. Writ sntncs that dscrib and xplain th contnts of your rport. 2. Sktch how th rport should look. Considr ths issus in planning your rport: What typ of rport is this dtail, summary, customizd, multipanl, a combination of typs? What dfins th columns of th rport variabls, computd variabls? What dfins th rows of th rport an obsrvation, summaris of obsrvations, groups of obsrvations? How should th rows b ordrd? What kind of annotation is ndd in th rport customizd lins, titls, footnots? 3. Undrstand your data. Considr ths issus whn you invstigat th contnt and structur of your analysis data sts: What data sts do you nd to produc th rport? How ar th analysis data sts structurd? Run PROC CONTENTS or viw th proprtis to rviw th attributs of th variabls in th data sts and th charactristics of th data sts, such as siz and sorting. List a fw obsrvations with PROC PRINT to s what th valus look lik. Whn producing a summary rport, run PROC FREQ on th variabls that dfin th catgoris in your rports to dtrmin th numbr of lvls and whthr valus should b groupd. This will hlp you prdict th physical siz of th final rport. Considr whthr PROC FORMAT would b usful in grouping th data. Run PROC MEANS to dtrmin rangs of valus. Is th physical structur of th data st in th sam orintation as th rport? Do you nd to rshap th data sts? What mthod should you us to rshap th data DATA stps, PROC TRANSPOSE, output data st from a procdur? Do you nd to combin data sts? How should you combin data sts MERE or SET statmnts in DATA stps, PROC APPEND, PROC SQL?
Chaptr 1 Writing Rports with SAS 7 Do you nd to comput nw variabls? If so, should you do this bfor you xcut th rport-writing procdur? If you r using PROC REPORT, you may not know th answr until you tst your PROC REPORT stp. Whn writing a DATA stp to produc a rport, you may b abl to comput th nw variabls and produc th rport in th sam stp. Do you nd to rarrang th ordr of th data for th rport? You may not know th answr to this qustion until you slct th rport-writing procdur. Say, for xampl, that your goal is to produc a dtail rport with ordrd rows. If you us PROC PRINT, your data st must b sortd or indxd in th propr ordr bfor you xcut PROC PRINT. If you us PROC REPORT, you may not hav to sort th data st bfor using th procdur. Options within PROC REPORT th ORDER or ROUP option on th DEFINE statmnt and th ORDER= option on th PROC REPORT statmnt will ordr th rows of your rport. 4. Slct th rport-writing procdur or dcid to us a DATA stp and, aftr rshaping th data sts as xplaind in Stp 3, writ th basic statmnts that construct th rport. Ensur that your program can construct th basic layout of th rport, and do not dwll on formatting th rport (formatting columns, adding labls, adding styl options, tc.). It may tak svral tris to achiv th rquird structur, and you may nd to rturn to Stp 3 to larn mor about your data sts, rshap th data sts, or comput nw variabls. Rfr to Tabl 1.2 for a list of which procdurs prform bst at which tasks. 5. Add formatting faturs to th rport. Considr whthr to add ths itms to improv th look of your rport: SAS dfind formats and usr-dfind formats titls, footnots, labls customizd lins styl attributs for fonts, spacing, bordrs, tc. customizd BY lins summary lins faturs spcific to th output dstination Your final rport program will likly b a hybrid of formatting faturs availabl within th procdur and thos that can b supplid with ODS spcifications. Rfrncs Th focus of this book is th prsntation of xampls, not th xplanation of syntax. Thrfor, it s important to hav rfrnc documntation availabl whn you rad this book. SAS 9 documntation is availabl onlin at support.sas.com/v9doc. Basic rfrncs usd for this book includ: SAS 9.1 Languag Rfrnc: Concpts SAS 9.1 Languag Rfrnc: Dictionary
8 SAS uid to Rport Writing: Exampls Bas SAS 9.1 Procdurs uid SAS 9.1 Output Dlivry Systm: Usr s uid Additional SAS xampls can b found in th many books availabl through SAS Prss. S th back of this book for a list of titls, and accss th SAS Prss Wb sit (support.sas.com/sasprss) for nwly rlasd and rvisd publications. Svral prsntations at SUI confrncs show how SAS usrs apply rportwriting tchniqus. Rcnt confrnc procdings ar availabl onlin, and thy provid a walth of additional applications and xampls. You can link to thm through th SAS support Wb sit (support.sas.com).