Locally Written SAS Macros

The SAS macros below were written and are maintained by Mayo Clinic staff. They contain SAS source code, a brief description of the macro's function and an example of the macro call.

This software is free. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

These macros are distributed with helpful intent, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Please give credit where credit is due. If you use functions from Mayo Clinic, please acknowledge the original contributor of the material.

General SAS Macros


Exact confidence intervals for a proportion. This macro calculates exact binomial confidence intervals for the binomial parameter P, after having observed X successes in N trials. Output includes normal and poisson approximation to the binomial. Erik Bergstralh. [08/2008]
boot Macro for selecting bootstrap samples. Erik Bergstralh. [08/2008]
dist Estimates the distance matrix between two groups (e.g. cases and potential controls) on the basis of a set of X's. The macro has an optional call to the VMATCH macro which allows one to perform variable optimal matching. Requires VMATCH if you wish to use the optimal matching option. This macro is designed to find a best cutpoint of a continuous variable based on chi-square statistics for a binary outcome. This macro also requires that you download nobs. Erik Bergstralh & Jon Kosanke. [11/2003]
findcut Uses the method of Contal and O'Quigley (1999) to find the best cutpoint in a continuous variable with regards to a survival outcome. Stephen Cha, Jay Mandrekar, Sumithra Mandrekar, Jeff Meyers. [04/2015]
gmatch Computerized matching of cases to controls using the greedy matching algorithm with a fixed number of controls per case. Controls may be matched to cases using one or more factors (X's). Erik Bergstralh & Jon Kosanke. [10/2003]
jitplot Produce Gplot of continuous variable(y-axis) vs a group variable(x-axis) in such a way that no points are hidden. This type of plot is most effective when N is not large and you wish to display all of the data points. Erik Bergstralh. [08/2008]
logisuni Univariate logistic regression model summaries with multiple dependent variables and predictors. Ross Dierkhising. [2/2011]
match Match one or more controls to each of a set of cases. Has been superceded by the %VMATCH and %GMATCH macros. Erik Bergstralh & Jon Kosanke. [4/1995]
mccc Computes Lin's concordance correlation coefficient (CCC) for any number of raters. Ross Dierkhising. [05/2011]
mcstrat This macro analyzes case-control studies where cases and controls are matched. It is a replacement for the SAS Version 5 procedure PROC MCSTRAT. Rob Vierkant & Jon Kosanke. [10/2009]
nesttest Conducts likelihood ratio tests for nested logistic and Cox proportional hazards models. Ryan Lennon. [03/2009]
outsumm Creates a single RTF file containing multiple tables created by %SUMMARY. Ryan Lennon. [10/2017]
plotcorr Proc Plot with correlation/regression statistics appended. This macro will produce a Y*X scatter plot with correlation and regression data appended at the bottom of the page. The macro can use either plot of Gplot. For Gplot the graph can optionally include the regression line of Y on X along with confidence limits for either mean Y or individual predicted Y's. Erik Bergstralh. [08/2008]
plotmat Create a scatterplot matrix graphically displaying the bivariate relationships between a number of variables. Rob Vierkant. [04/2003]
regress Summary of association between X and Y. This macro performs ploynomial regression analysis on Xvar with the option of first eliminating outliers. It provides descriptive statistics on Xvar and Yvar and performs tests of modeling assumptions. C. D. STERTZ & Susanne L. Daood. [03/1994]
rocplus Estimated Integrated Discrimination Index (IDI) and Net Reclassification Improvement (NRI) for comparison of a new risk model to an old model. Ref: Pencina, et al. Stat Med. Erik Bergstralh. [03/2011]
summary Creates a table of variable summaries plus test statistics for the difference between two or more independent samples. The results can be output to a Rich Text File (RTF). The user can choose from a list of summary options for continuous, discrete, ordinal, and survival data and choose the order in which variables are ordered on the table. Ryan Lennon. [02/2018]
symmchk Checks for symmetry and suggests the best power transformation, if one exists, to make an asymmetric distribution symmetric. Stephen Cha. [07/2009]
uagreemt Measures agreement, precision, accuracy, total deviation index and coverage probability. Wenting Wu. [02/2009]
vmatch Computerized matching of cases to controls using variable optimal matching. The number of controls per case is allowed to vary with only the total fixed. Controls may be matched to cases using one or more factors (X's). VMATCH uses the case/controls distance matrix as input. This distance matrix can be calculated using the DIST macro, which includes an optional call to VMATCH. For SAS V9.3 and higher. Erik Bergstralh & Jon Kosanke. [04/2014]
Survival Analysis SAS Macros
comprisk Performs Cumulative Incidence in presence of competing risks. E. Bergstralh. [08/2008]
criskcox Competing risk survival analysis with covariates. Walter Kremers, Erik Bergstralh & Terry Therneau. [12/2012]
phlev Leverage residuals for proportional hazards model. This macro returns the leverage residuals matrix L for a proportional hazards model. The returned residuals data set is n by p, where n is the number of (non-missing) subjects used in the PHREG fit, and p is the number of fitted covariates. The leverage residuals are an approximation to the jackknife; the i-th observation of the data set contains the approximate change in beta if observation i were dropped from the model. These residuals will normally be plotted as an aid to finding influential or "high leverage" observations.The procedure can also estimate the robust covariance estimate L'L. Terry Therneau, Erik Bergstralh & Jon Kosanke. [01/2002]
In SAS version 8.1 the %phlev macro is no longer necessary. Robust variance estimates are available directly from phreg using the covsandwich option.
schoen Schoenfeld residuals for proportional hazards model. This macro returns Schoenfeld residuals and scaled Schoenfeld residuals from the Cox model. The Schoenfeld residuals(r) are defined only at event times. Erik Bergstralh, Terry Therneau & Ryan Lennon. [01/2011].
surv Complete Kaplan-Meier survival analysis with printing options and logrank statistic. This macro will calculate the general survival statistics (p(t), standard error, confidience limits, and median survival time. It will also do the k-sample logrank and plotting upon request. Terry Therneau & Jan Offord. [12/1999]
survcstd Calculates the c-statistic (concordance, discrimination index) for survived data with time dependant covariates and corresponding SE and 100(1-alpha)% CI. Walter Kremers. [10/2008]
survlrk Calculates logrank statatistics for the surv macro. Returns an output dataset. David J. Camp, modifications by Erik Bergstralh & Jan Offord. [09/1993]
survplot Creates high-quality and easily customized Kaplan-Meier plots. Can be used to report the number at risk or the Kaplan-Meier estimate at specific time intervals below the plot. May also add group labels and the log-rank p-value to the plot and accepts user-specified axes, legends, and annotate data sets. Ryan Lennon. [08/2009]
survlt General survival statistics p(t), standard error, confidence limits, and median survival time, for the left-truncated survival analyses. This macro replaces the previous SURVTD macro. This macro does not do any testing or support multiple event data. Jan Offord, Chris Scott, Terry Therneau & Erik Bergstralh. [08/2009]