GFORMULA 3.0 – The parametric g-formula in SAS

The GFORMULA macro implements the parametric g-formula (Robins, 1986) to estimate the risk or mean of an outcome under hypothetical treatment strategies sustained over time from longitudinal data with time-varying treatments and confounders. To download software, documentation and sample code (version January 2019) click here.


The GFORMULA_RCT macro implements the parametric g-formula in SAS to estimate the per-protocol effect in randomized trials with protocol deviations. To download software, documentation and sample code (version June 2019) click here.

Requires the external SAS macro gformula3.

Marginal Structural Cox Models

This sample program shows how to use SAS to estimate the parameter of a marginal structural Cox model via inverse probability weighting. An earlier version of this program appeared in the appendix of Hernán, Brumback, and Robins (2000). This article shows how to use STATA to do the same thing.

MSM – Structural models for survival analysis in SAS

MSM is a set of SAS macros to estimate the parameters of a marginal structural Cox model and estimate risk under hypothetical static interventions.The SAS Package IML is needed to run this program.

Questions? Contact Roger Logan

Simulating data from a Structural Nested Accelerated Failure Time Model

To download the sample SAS program click here. For a description of the simulation procedure see this paper by Young JG, Hernán MA, Picciotto S, Robins JM.

Initiators SAS macro

The INITIATORS macro is designed to analyze observational longitudinal data to estimate the effect of interventions sustained over time. The macro can conduct the observational analogs of the intention-to-treat and per-protocol analyses (see documentation). All analyses are conducted using pooled logistic regression to approximate the hazard ratio from a proportional hazard Cox model.

Questions? Contact Roger Logan.

SNCFT – Structural Nested Cumulative Failure Time Models in SAS

The SNCFTM macro implements g-estimation of the parameters of a Structural Nested Cumulative Failure Time Model, and estimation of risk under a hypothetical static intervention on a binary time-varying treatment.

Questions? Contact Sally Picciotto

Picciotto, S., Hernán, M. A., Page, J.H., Young, J.G., Robins, J.M. Structural Nested Cumulative Failure Time Models to Estimate the Effect of Hypothetical Interventions. JASA 2013.

Partial Identification Using Instrumental Variables in SAS

The IV_BOUNDS macro provides bounds under various sets of assumptions, for Pr[Y(0)=1], Pr[Y(1)=1], and the average treatment effect for a binary treatment.

Questions: Contact Sonja Swanson

Swanson SA, Hernán MA, Miller M, Robins JM, Richardson T. Partial identification of the average treatment effect using instrumental variables. JASA 2018; 113(522):933-947.