Skip directly to search Skip directly to A to Z list Skip directly to navigation Skip directly to page options Skip directly to site content

Sample Code

Below is a listing of all the sample code and datasets used in the Continuous NHANES tutorial. They are organized by module and then task. If a module or task is not listed it is because it did not have a related program. Programs are available as SAS programs (i.e. SAS Survey Procedures and SAS-callable SUDAAN) and Stata programs. The datasets are SAS or Stata datasets for Windows.

These datasets are intended to be used with the tutorial only, as they may contain a subset of the variables available. If you wish to conduct your own analyses, please download the most current and complete datasets from the NHANES website.

Program code used in this tutorial follow procedures available in SAS 9.2, SUDAAN 9.0 or SUDAAN 8.0, and Stata/SE 10.0. Additional programs for SAS 9.1 and R are available at the bottom of this page.

These programs use variable formats listed in the Tutorial Formats page. You may need to format the variables in your dataset the same way to reproduce results presented in the tutorial.

A regular left-click may not download the SAS datasets or SAS code correctly. Your browser may try to open and attempt to interpret the contents of the dataset or program. If this happens, right-click the link and save the dataset or program to your hard drive. After it has downloaded, the use your statistical software program to open the dataset to view it.

Download Data Files

Task 3: How to Extract and Copy NHANES Data Files to Permanent Libraries

Task 3c: How to Import and Save NHANES Data Files in Stata

Append & Merge Datasets

Task 1: How to Append NHANES Data

Step 1: Check Contents of Datasets
Step 2: Append Directly, if Contents are the Same
Step 3: Rename Variables and then Append
Step 4: Check Results

Task 2: How to Merge NHANES Data

Task 1c and 2c: How Append & Merge NHANES Data in Stata

Clean & Recode Data

Task 1: How to Identify and Recode Missing Data

Step 1: Identify Missing and Unavailable Values
Step 2: Recode Unavailable Values as Missing
Step 3: Evaluate Extent of Missing Data

Task 2: How to Identify and Recode Skip Patterns in NHANES Data

Step 2: Check Data for Skip Patterns
Step 3: Recode Skip Pattern

Task 3: How to Identify Outliers and Evaluate Their Impact

Step 1: Check Distributions
Step 2: Plot Graph of Survey Weight Against Distribution of Variable
Step 3: Identify Outliers and Compare Estimate with and without Outliers

Task 4: How to Create Derived Variables from NHANES Data

Step 1: Recode Based on Alternate Definitions
Step 2: Check Derived Variables

Task 1c, 2c, 3c, and 4c: How Clean & Recode NHANES Data in Stata

Format & Label Variables

Task 1: How to Format and Label NHANES Variables

Task 1c: How Format & Label NHANES Data in Stata

Save Datasets

Task 1: How to Save Datasets

Task 1c: How Save NHANES Data in Stata

Variance Estimation

Task 3: How to Calculate Degrees of Freedom for Performing Statistical Tests and Confidence Limits

Optional: Calculate alternate confidence intervals

Descriptive Statistics

Task 1a: Check Frequency Distribution and Normality

Step 1: Use the univariate procedure to generate descriptive statistics in SAS
Step 3: Request selective statistics and output results to SAS dataset

Task 1c: How to Check Frequency Distribution and Normality in Stata

Step 1: Use the summarize command to generate weighted summary statistics for a population subset
Step 3: Use tabstat to request selective statistics

Task 2: Generate Percentiles

Task 3a: Generate Means Using SUDAAN

Step 1: Use proc descript to Generate Means in SUDAAN
Step 4: Use proc descript to Generate Geometric Means in SUDAAN

Task 3b: Generate Means Using SAS Survey Procedures

Task 3c: Generate Means Using Stata

Step 2: Use svy:mean to generate means and standard errors in Stata
Task 4a: Generate Proportions Using SUDAAN

Hypothesis Testing

Task 1a: Set Up a t-test in NHANES Using SUDAAN

Step 1: Set Up SUDAAN to Produce Means
Step 3: Perform t-test to Test for Significance

Task 1b: Set Up a t-test in NHANES Using SAS

Step 2: Set Up SAS Survey Procedures to Produce Means
Step 4: Perform t-test to Test for Significance (SAS Survey Procedures 9.2)

Task 1c: Set Up a t-test in NHANES Using Stata

Task 2a: Generate Confidence Intervals for Geometric Means Using SUDAAN

Task 2c: Generate Confidence Intervals and Geometric Means Using Stata

Task 3a: Perform Chi-Square Test Using SUDAAN

Task 3b: Perform Chi-Square Test Using SAS Survey Procedures

Task 3c: Perform Chi-Square Test Using Stata

Age Standardization and Population Counts

Task 1a: How to Generate Age-Adjusted Prevalence Rates in SUDAAN

Step 1: How to Generate Age-Adjusted Prevalence Rates in SUDAAN
Optional Step 2: How to Generate Age-Adjusted Means
Step 1: How to Generate Age-Adjusted Prevalence Rates in SAS Survey Procedures 9.2
Optional Step 2: How to Generate Age-Adjusted Means in SAS Survey Procedures 9.2

Task 1c: How to Generate Age-Adjusted Prevalence Rates in Stata

Step 1: How to Generate Age-Adjusted Prevalence Rates in Stata
Optional Step 2: How to Generate Age-Adjusted Means in Stata

Task 2a: Generate Population Counts in SUDAAN

Task 2b: Generate Population Counts in SAS Survey Procedures

Task 2c: Generate Population Counts in Stata

Linear Regression

Logistic Regression

Additional Programs for SAS 9.1

Hypothesis Testing - Task 1b: Set Up a t-test in NHANES Using SAS

Step 4: Perform t-test to Test for Significance (SAS Survey Procedures 9.1)

Age Standardization-Task 1b: How to Generate Age-Adjusted Prevalence Rates in SAS Survey Procedures

Step 1: How to Generate Age-Adjusted Prevalence Rates in SAS Survey Procedures 9.1
Optional Step 2: How to Generate Age-Adjusted Means in SAS Survey Procedures 9.1

Linear Regression

Task 2b: Set Up Linear Regression using SAS Survey Procedures 9.1

Logistic Regression

Task 2b: How to Use SAS Survey Procedures 9.1 to Perform Logistic Regression

To report problems or comments, use the NHANES Web Tutorial email. Do not direct questions to this email address, as it can only receive feedback and we will not be able to reply.

TOP