Healthy Eating Index SAS Code
This webpage provides SAS code for different methods for calculating the HEI. To learn more about a particular method, visit Overview of the Methods and Calculations, Mean Ratio Method, Population Ratio Method, Bivariate Method, or Multivariate MCMC Method.
The code provided below is for the SAS software package. Please direct questions about the HEI SAS code to RFAB@mail.nih.gov.
Researchers are encouraged to ask questions and share their code via the HEI list-serv. To join the HEI list-serv, send an email to email@example.com with SUBSCRIBE HEI <first name> <last name> in the body of the text (remove > and <, for example: SUBSCRIBE HEI John Smith).
In the table below, sample SAS code is available for calculating the HEI with different dietary assessment tools. These include:
- 24-hour recall(s) example: Automated Self-Administered 24-Hour Dietary Assessment Tool
- National Health and Nutrition Examination Survey: NHANES weighted national survey with 24-hour recall(s) example
- Cohort with food frequency questionnaire example: NIH-AARP Diet and Health Study: NIH-AARP
Where possible, the zip files provided include sample SAS code, macros for scoring, and sample output. These macros can be used to calculate HEI–2015, HEI–2010, and HEI–2005 component and total scores and can be applied to any SAS dataset containing the requisite variables.
HEI-2015 includes only the macro for scoring, as legumes (beans and peas) are now allocated to both the vegetable and protein food groups. For some applications, such as an analysis of the food environment, the scoring macro can be used (provided below).*
In the 2010 and 2005 versions, there are two macros, one of which allows for the allocation of legumes (beans and peas) to count as part of the vegetable or protein food groups, and the other creates ratios and scores them using the applicable standards.
Download HEI Sample Code
Click each to expand for more information.
Simple HEI Scoring Algorithm - Per Day
Simple HEI Scoring Algorithm - Per Person
Population Ratio Method
Multivariate Markov Chain Monte Carlo (MCMC) Method
The MCMC method estimates the distribution of HEI component and total scores. The method addresses measurement error, episodic consumption, skewness, and the correlation between the components and energy.
MCMC SAS code for the HEI-2015 (including a wrapper) [ZIP - 4.25 MB] is available here. Although this example is for NHANES 2011-12 data, the programs can be used with other cycles of NHANES and any data with a similar survey structure with BRR weights. For analyses using other types of weights, additional modifications would be needed. Please note that this code may take 1 to 3 days to run.
HEI-2010 and HEI-2005
The MCMC approach has been described for the HEI–2005 by Zhang et al. 2011 and applied in the Evaluation of the HEI–2010. SAS macros for the implementation of this approach are available here.
For more information about NHANES analyses with the HEI, see the Frequently Asked Questions page, including the question “What information do I need when utilizing National Health and Nutrition Examination Survey (NHANES) data to calculate HEI scores?“