NHANES file-merging guide
How should NHANES data files be merged?
Write merge rules as a reviewable file-handoff brief Requested outputs / delivery goal: Merge-rule documentation, a component-matching checking table and a sample-flow record draft.
First check that both files belong to the same survey cycle and each has one row per participant. Then use SEQN to verify one-to-one matching. Separate changes in merged row counts into component eligibility, file matching and special field codes; do not label them all missingness or loss to follow-up.
This guide illustrates only a within-cycle horizontal join of the official CDC/NCHS 2017–2018 demographics file DEMO_J and blood-pressure/cholesterol questionnaire file BPQ_J. It addresses files and participant flow, not hypertension prevalence, effect estimates or causal conclusions. Counts below were summarized from SEQN in the two official XPT files and checked against their Codebooks.
A concrete task with RigorMed
Write merge rules as a reviewable file-handoff brief
These are suggested task inputs and outputs to request, not a new execution, a customer outcome or a guarantee of completion.
Materials to provide: Confirmed cycles, an official file list, SEQN and record-granularity documentation, and existing matching summaries.
Requested outputs / delivery goal: Merge-rule documentation, a component-matching checking table and a sample-flow record draft.
An example request
Using the components and actual summaries I provide, organise the merge order, SEQN relationships, eligible populations and matching checks. Flag one-to-many cases requiring tests. Without execution records, do not claim that merging succeeded.
What still needs review
This page's actual counts come from the listed official files. Do not copy them as your own data or call component ineligibility loss to follow-up.
Fix the sources and record granularity first
Both files are publicly released NHANES 2017–2018 components. Do not apply this example directly to different cycles or components with multiple rows per person.
| File | What to confirm | Checks in this example |
|---|---|---|
| DEMO_J.XPT | Demographics Codebook, SEQN and RIDAGEYR; verify one row per person | 9,254 rows; SEQN is non-missing and unique; 6,161 participants are aged ≥16 years |
| BPQ_J.XPT | Blood-pressure questionnaire Codebook, SEQN and BPQ020; verify eligible ages and one row per person | 6,161 rows; SEQN is non-missing and unique; official documentation specifies participants aged 16 years or older |
BPQ_J eligibility comes from its Eligible Sample section and BPQ020 Codebook. The demographics-file count is not the research denominator for BPQ020. Check component eligibility and the join key before defining eligibility rules for the specific question.
Five checks before and after merging by SEQN
Use only official files from the same cycle
Obtain DEMO_J.XPT and BPQ_J.XPT through the CDC/NCHS links below and open their Codebooks. Record cycle, component, access date, eligible population and variable definitions. Similar filenames or third-party mirrors do not replace source verification.
Check keys rather than concatenating columns immediately
Count rows, non-missing SEQN values and duplicate SEQN values separately. Here DEMO_J has 9,254 unique keys and BPQ_J has 6,161, with no missing or duplicate keys on either side. A participant-level one-to-one merge can therefore be checked in this example. For one-to-many matches or duplicates, revisit component documentation to establish record granularity instead of arbitrarily deduplicating.
Audit matches with an outer join, then select the join required for analysis
Outer-join by SEQN while retaining source indicators: 6,161 are present on both sides, 3,093 only in DEMO_J and 0 only in BPQ_J. With DEMO_J as the left table, a left join retains 9,254 rows, but 3,093 have no BPQ fields. An inner join or BPQ_J-based join has 6,161 rows. The join type follows the question and component eligibility, not a desire for a larger number.
Explain the 3,093 participants rather than calling them lost to follow-up
Inspect the DEMO_J-only records: all 3,093 are younger than 16, while all 6,161 participants aged 16 or older match BPQ_J. This agrees with BPQ_J's official age eligibility. The difference of 3,093 reflects component eligibility in this example; it is not longitudinal loss to follow-up and cannot be generalized to other cycles or components.
Then check field codes and the research sample
BPQ020 asks whether a doctor or other health professional has ever told the participant they have hypertension; it is not measured blood pressure at this examination. Both Codebook and file show 2,137 'yes', 4,014 'no' and 10 'don't know' responses. If a prespecified analysis retains only yes/no responses, 6,151 answers are available. Do not treat code 9 as a numeric measurement or attribute these 10 responses to file merging. Further study rules must separately define age, missingness in other fields, applicable weights, strata and PSUs.
Record the two kinds of count changes separately
The table checks unweighted participant counts in these official files. It is neither a population estimate nor the eligibility flow for a formal analysis.
| Check stage | Count | Interpretation |
|---|---|---|
| DEMO_J participants | 9,254 | All demographics-component records; unique SEQN |
| DEMO_J only | 3,093 | All are younger than 16 in this example, outside BPQ_J's eligible age range |
| DEMO_J matched to BPQ_J | 6,161 | One-to-one SEQN matches; 0 BPQ_J-only records |
| BPQ020 answered yes or no | 6,151 | Another 10 answers are don't know; this illustrates field-code checking, not a formal study sample |
Reproducible procedure: read each official XPT, retaining SEQN plus RIDAGEYR from demographics and BPQ020 from the questionnaire. Check SEQN uniqueness on each side, outer-join the keys and count both, left_only and right_only. Within left_only, count RIDAGEYR < 16. Finally, count BPQ020 codes 1, 2 and 9 according to its Codebook. R, SAS or Python can reproduce these counts; they do not depend on one program's automatic filtering.
A within-cycle horizontal join is not cross-cycle stacking
Here SEQN links the same participant across two person-level files in one cycle. Cross-cycle analysis also appends records from different cycles and requires item-by-item checks of definitions, measurement methods, coding, design and weights. Do not transfer this example's join type, counts or weights directly to another cycle.
This example performs no complex-survey estimation and does not establish that RigorMed can automatically merge arbitrary NHANES files. A formal study should first freeze its question and eligibility rules, check the actual components' Analytic Notes, then select appropriate survey weights, strata, PSUs and missing-data handling.
Frequently asked questions
Why does demographics have 9,254 participants but the blood-pressure questionnaire only 6,161?
BPQ_J's official eligibility here is age 16 or older. Comparing the files shows that all 3,093 demographics-only participants are younger than 16. The count difference must not be called data loss, refusal or loss to follow-up without further evidence.
Can every NHANES file be merged one-to-one by SEQN?
No. Determine whether a row in each component represents a participant, a repeated record or another unit, and check missing and duplicate keys. This matching check applies only when one-to-one structure is demonstrated for the actual components and cycle.
Are the 6,161 merged participants automatically the formal analysis sample?
No. BPQ020 has special response codes, and other research variables have their own eligibility and missingness. A formal sample depends on the prespecified question, eligibility criteria, complete data requirements, survey weights and analysis plan.
Verified sources
The official sources below were checked on 2026-09-28 / RigorMed: 2026-10-13. Access conditions and update dates are rechecked before publication.
- CDC/NCHS: 2017–2018 DEMO_J demographics data and Codebook
- CDC/NCHS: official 2017–2018 DEMO_J XPT file
- CDC/NCHS: 2017–2018 BPQ_J questionnaire data and Codebook
- CDC/NCHS: official 2017–2018 BPQ_J XPT file
- CDC/NCHS: 2023–2024 SAS merge-code example—join methods only
- CDC/NCHS: NHANES survey methods and analytic guidelines
Start with a specific task
Write merge rules as a reviewable file-handoff brief
Bring legally usable materials and this page's example request to the workspace. Check the pre-execution material and credit notices before confirming, then review the resulting outputs.
