SAS and R

Examples of tasks replicated in SAS and R

Catalogs of posts

  • Statistics Examples
  • Probability/Mathematics Examples
  • Simulation Examples
  • Graphics Examples
  • Programming Examples
  • Examples 7.1 - 7.42
  • Examples 8.1 - 8.42
  • Examples 9.1 - 9.38
  • Examples 10.1 - 10.8
  • Examples 2014.1 ... 2014.N
  • Non-example posts

Non-example posts

These are some of our most popular posts that aren't exactly examples.

RStudio in the cloud, for dummies

Really useful R package: sas7bdat

Managing projects using RStudio

The Statistical Sleuth (second edition) in R

Citing R or SAS

SAS Macro Simplifies SAS and R integration

Proc tabulate for simple statistics

To attach() or not attach(): that is the question

Tools to tidy up R code

A plea for consistent style!

Complex survey design support
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Home
Subscribe to: Posts (Atom)

Subscribe to SAS and R!

RSS: Or: Get SAS and R by Email

Search the SAS and R Blog

The book (second edition, 2014)

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


Buy a book

SAS and R: Data Management, Statistical Analysis, and Graphics, Second Edition

Using SAS for Data Management, Statistical Analysis, and Graphics

Using R for Data Management, Statistical Analysis, and Graphics

Recent Comments

Loading...

About the authors

Nicholas Horton is a Professor of Statistics at Amherst College. He is a biostatistician with expertise in missing data methods, longitudinal regression, statistical computing and statistical education. Nick's home page; Nick's Google Scholar author page

Ken Kleinman is an Associate Professor with the Department of Biostatistics and Epidemiology at the University of Massachusetts, Amherst. He is a consulting biostatistician with expertise in group-randomized trials and disease surveillance; he also offers R training courses. Ken's home page; Ken's Google Scholar author page.
Sidebar list of all entries.

Blog Archive

About SAS and R

This blog is where we post additional examples for our books about SAS and R (Amazon: SAS and R.)

Please also visit the web site for the book, where code from the book and additional information are available.

Another resource is the StatSoftEquivs wiki. You can add to it!

Blogger only allows one author per post, but we collaborate actively on most entries and share credit and responsibility.

Creative Commons License
SAS and R blog by Ken Kleinman and Nicholas Horton is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Topics discussed

%sysevalf 3D plots a*b=c syntax abline() adaptIntegrate() adding text to graphics adjacent observations age distribution aggregated datasets Alan Zaslavsky Amazon Sales rank Amazon web services amherst annnotate data sets annotate data set annotate macro anova() API apply family of functions apply() arrange() array statement arrays as.data.frame() as.factor as.factor() as.numeric() as.POSIXlt() assessing differences association measures association plot assumptions attach() axis axis control axis statement back-to-back barplots barchart() function bargraph.CI() function barplot() barplots(back to back) baseball bayes statement Bayesian methods Benjamini and Hochberg Benjamini-Hochberg binning binom.test() binomial probability Bland-Altman plot blog aggregators Bonferroni procedure boxplot brute force bubble plot Bureau of Labor Statistics by statement C() calculus call symput capture.output() cat() categorical covariates categorical data causal inference ceil ceiling() censored data central limit theorem central moments cex change variable types chi-square test chisq.test() choropleth Chris Wild circles citation() citing R citing SAS class probabilities class statement clodds statement Clopper-Pearson CI cloud computing clustering coda package coef() function col option college majors colnames() colors communicating between SAS and R comparing models comparisons complex survey design conditional execution conditioning confidence intervals confint() confounding connect points Contour contrast statement contrasts convert categorical class to numeric Convert R to SAS convert SAS to R correlated data models count models coverage probabilities Cox proportional hazards model CPAN CPAP Cramer's V CRAN crowd-sourcing cubature library cumulative distribution function cumulative hazard custom graphics layout customizing plots cut function cyclemeter data frames data science data step date and time values date formats ddf option debugging densityplot() deparse function deparse(substitute() descriptive statistics design matrix Design package detach() determinant Digital Ocean digits of Pi dim() diploma problem Dirk Eddelbuettel distance do loop do() Docker dotplot dotplot/boxplot dplyr drop statement dummy variables duplicated data Durbin-Watson statistic dynamite plot Edward Tufte elrm package empirical CDF empirical problem solving end = epidemiology estimate statement eval statement events/trials syntax exact CI exact logistic regression exact statement Excel excerpt exchangeability exp() expand.table() expected cell counts expected value exponential factor analysis factor() failure time analysis false discovery rate favstats() Fibonacci series file print file.info() file() finite mixture models Firth logistic regression Firth option fitted() flexmix package FLXMRglmfix function FLXPmultinom function fonts for() foreign library formatted output formatting fractions frailty models function() functions Galton Gamma function gather() gdata package generalized pairs plots GGally package ggformula package ggformula: another option for teaching graphics in R to beginnersdata science ggplot2 package git Github glm.nb() function glm() function gls() gmodels package goodness of fit google spreadsheet gps grammar of graphics graphics grep() function grid.polyline() function grid.text() function group option gsub() Hadley Wickham hat-check problem hazard function heat map HELP data set hexagon hexbin package hexbin() hilo interpolation HistData package histogram Hochberg procedure homogeneity homoscedasticity Hosmer and Lemeshow Hotelling's T href option ifelse() imputation indicator variables informal inference input statement integrated development environment integration interaction interactive development environments JAGS James-Stein estimator job creation John Emerson John Snow Kaplan-Meier estimates Ken Beath kurtosis kurtosis() ladd() lag function lapply() lapply() function large datasets latent class analysis latent class model latent class models lattice library lawstat package layout.show() layout() le Cessie and Houwelingen legend legend statement legend() levene.test() function Levene's test libraries in R linear regression lines() list of variables log scale logic logic tests logistf package logistic regression looping Louis Aslett lurking variables make categories manifest variable MANOVA mapply() function mapproj package maps maps package Markdown markerattrs Markov Chain Monte Carlo MASS library MASS package match() match() function matlines() matplot() matrices matrix matrix operations matrix() Matt Regan Matt Shotwell Maxine Pfannkuch MCMC MCMCpack package mdy function mean() measures of association median regression merge merge statement methods() Metropolis-Hastings algorithm mice package mice() Michael Friendly Michael Weylandt Minard minimum missing data missing data modeling mixtools package mod mod function mode=include modeling language moments package Monte Carlo experiments Monty Hall problem mosaic package mosaic plot Mplus MplusAutomation package mtext() multinomial observations multiple comparisons multiple imputation multiple regression multivariate normal multivariate statistics mvrnorm() na.string name conflict names(). events/trials syntax negative binomial distribution negative binomial regression Nelson-Aalen estimator new variables New Year's resolutions nlme nobs option non-monotonic missingness normality assumption NP complete null hypothesis numeric() observed cell counts odds ratio ods graphics on ods output statement ods system offset axes offset option one-to-many one-way chi-square test open source OpenBUGS options() order order() outer() function output statement overlay option p.adjust() p.adjust() function pairs plots pairwaise comparisons panelby statement par() parameterization partykit package paste() pathological distribution pattern statement pch pdf function perl permutation test Philips Pi pie() function plot plot colors plot symbols plot.ts() plot() plotFun() plotrix package plotting functions Plus 4 estimator pnbinom() point option pointlabel option Poisson distribution Poisson regression poLCA package polygon() pool() population age power calculations power via Monte Carlo ppois() predictive mean matching principal components probability probability distributiholons probability distributions proc fcmp proc fmm proc freq proc gchart proc genmod proc glm proc gmap proc gplot proc gproject proc greplay proc import proc kde proc lca proc logistic proc mcmc proc mi proc mianalyze proc mixed proc multtest proc phreg proc rank proc sgpanel proc sgplot proc sgrender proc simnormal proc standard proc surveyselect proc tabulate proc template proc transpose proc univariate proc_r productivity profile likelihood programming style Project MOSAIC projects prop.test() propensity scores proportional hazards assumption pseudo-random numbers psychology put pyramid plots qt() quadratic equation quantile function quoting R R environments R function R Inferno R packages R-bloggers R-sig-teaching R2winbugs radio static ragged input rand function random number generation random numbers random statement random variables randomization randomLCA package range of variables rare disease assumption rbind() RColorBrewer RColorBrewer package RCurl package read complex data files read data by byte Read data in R Read data in SAS read data in Stata format read Excel sheets read from local disk read from URL read sheets read.csv() read.sas7bdat() read.table() read.xlsx() readBin() readline() readLines() recursive partitioning reference value referencing sequential variables reflabel option regexp() regression adjustment regression to the mean regression trees regular expressions rejection sampling relative risk relevel function remainder rep() repeated multiples replicate() reproducible analysis resampling based inference reshape reshape package reshape() retain revision control systems rexp() Richard Heiberger Rick Wicklin Robert Allison rjags rnorm() robustness Rocker Rosettacode round function rounding rowMeans() function Royal Statistical Society rpart package RStudio runif() running average sample() sapply() SAS SAS data sets SAS formats SAS macro sas tricks SAS-x sas7bdat format sas7bdat package SAT scores save data in Stata format saving output from SAS scatterplot sciplot package SD card sd() seeds sensitivity sequences set ds; by x; set statement options set.seed() shading regions Shangri La shrinkage estimator shuffle() shuffle() function side by side histograms Simpson's paradox simulate data simulation studies skewness skewness() sleep apnea smoothScatter() snowstorms social networks social science sort sports statistics spreadsheet spreadsheets standard deviation standardized regression coefficients Stata statistical education Statistical Sleuth statistics education Stein estimator stratiification string functions string manipulation Stuart Lipsitz style guide subset subsetting substitute function substr summary statistics summary() sunflowerplot() survey sampling survival analysis survival model survival package symbol statement symbolic computation t-test t() t() function table() tables Task Views teacher salaries teaching statistics test statement text() textConnection() Thomas Lumley Tick marks tidying code tidyr Tim Hesterberg time series time-varying covariates title statement titles transpose truncated distribution ts() two sample comparisons Type I error rate type="n" unaggregated datasets University of Auckland unobserved class variable number of records variance vectors version control vref optioncall symput Wald CI Weibull weight statement where function which.min() function while() wide to narrow Wilcoxon rank-sum test Wilson estimator WinBUGS with() within() Wolfram Alpha World Statistics Day write Excel sheets writeXLS package xchisq.test() xckd Xin Wei ylim option