Sunday, October 30, 2011

Ken Beath, of Macquarie University, commented on an earlier entry that the best way to generate summary statistics is using proc tabulate. While the best tools might differ, depending on the purpose, we wanted to share Ken's code demonstrating how to replicate the R mosaic package tables using proc tabulate.

SAS

Ken's fully annotated code is appended below; we highlight the key syntax elements here. Reading in the data is shown in many examples.

The class and var statements serve their usual purpose of identifying the categorical and analysis variables. The table statement does the work of the procedure, specifying a table with rows (requested before the comma) for each level of substance and overall, with columns (requested after the the *) to include the listed statistics for the analysis variable cesd. The resulting table is shown below.

/* missing option create a category missing for each categorical variable, always a good idea; the table statement specifies row then column; so for this example we have substance defining the rows, and cesd statistics the columns */

No comments:

Subscribe to SAS and R!

Search the SAS and R Blog

The book (second edition, 2014)

Reviews (from the first edition)

"By placing the R and SAS solutions together and by covering a vast array of tasks in one book, Kleinman and Horton have added surprising value and searchability to the information in their book. … a home run, and it is a book I am grateful to have sitting, dust-free, on my shelf."—Robert Alan Greevy, Jr, Teaching of Statistics in the Health Sciences

"I use SAS and R on a daily basis. Each has strengths and weaknesses, and using both of them gives the advantage of being able to do almost anything when it comes to data manipulation, analysis, and graphics. If you use both SAS and R on a regular basis, get this book. If you know one of the packages and are learning the other, you may need more than this book, but get this book, too. "

Charles Heckler, University of Rochester, Technometrics

"Excellent cross-referencing to other topics and end-of-chapter worked examples on the ‘Health evaluation and linkage to primary care’ data set are given with each topic. … users who are proficient in either of the software packages but with the need to use the other will find this book useful."—Frances Denny, Journal of the Royal Statistical Society, Series A