- One row per patient, one column per variable — this single structural rule prevents more import errors than any other single fix.
- Statistical software reads every cell as one discrete value; merged cells, multiple tables on one sheet, and mixed data types in one column all break this assumption silently.
- Missing values need one single, consistent code — never a mix of blanks, "N/A," and text notes in the same column.
- Categorical variables need consistent coding — "Male," "male," and "M" are three different categories to a computer, even though they mean the same thing to you.
- A five-minute range and duplicate check in Excel, before you ever open your statistical software, catches most of the errors a reviewer would otherwise catch for you.
Why Data Cleaning Is Essential
Every statistical test assumes the data feeding into it is structurally correct — one value per cell, one consistent type per column, one row per case. When that assumption is violated, software doesn't usually stop and warn you; it either fails to import a portion of your data, misclassifies a variable's type, or silently pulls corrupted values into a calculation. The result looks like a normal analysis with a normal-looking p-value, but the number underneath it may be wrong.
Cleaning your data before analysis, rather than fixing problems after a strange result appears, is dramatically faster and far less error-prone. A spreadsheet built correctly from the start also makes your work reproducible — a co-author, a statistician, or a thesis committee member should be able to open your file and understand exactly what every column means without asking you.
There is also a time-cost argument that is easy to underestimate until you have lived through it once: diagnosing a strange result that turns out to be caused by a formatting problem often takes far longer than the data entry itself, because the symptom (an odd p-value, a variable that refuses to import as numeric, a sample size that doesn't match your enrollment log) rarely points directly back to its formatting cause. An hour spent designing a clean spreadsheet before data entry begins routinely saves several hours of troubleshooting weeks later.
How Statistical Software Reads Excel Files
Statistical software imports an Excel sheet by treating the first row as variable (column) names and every row below it as one case, reading each cell strictly as either numeric, text (string), or date, based on the column's dominant content. If a single cell in an otherwise numeric column contains text — a stray note like "check again" typed into a lab-value column — most software will read the entire column as text, silently disabling every numeric calculation on it.
This is exactly why structure matters more than appearance in a data-entry spreadsheet. A sheet that looks perfectly readable to a human, with helpful notes, colors, and merged section headers, can be functionally unreadable to statistical software, which has no concept of visual formatting and only sees rows, columns, and raw cell values.
Designing a Proper Spreadsheet
The foundational structure every statistical package expects is called "wide" format: each row is one patient (or one case), and each column is one variable measured on that patient. A sheet with 120 patients and 15 measured variables should have exactly 120 data rows and 15 data columns, plus one header row.
| Patient Data — Cardiology Ward | |
|---|---|
| Name | Details |
| Ahmed S. | Age 54, BP 140/90, DM: yes |
| Fatima R. | 62 yo, hypertensive, no diabetes |
| patient_id | age | sbp | dbp | diabetes |
|---|---|---|---|---|
| CARD-001 | 54 | 140 | 90 | 1 |
| CARD-002 | 62 | 150 | 95 | 0 |
Only use "long" format instead — where each row is one patient-timepoint combination — if your planned analysis specifically requires it (certain mixed models or GEE); most standard comparative analyses and calculators, including StatClinic's own data tools, expect wide format by default.
Variable Naming Conventions
Column headers should be short, consistent, and free of spaces and special characters — many statistical packages either reject these characters outright or silently convert them, causing confusion later. Use a data dictionary (a separate reference sheet or your Statistical Analysis Plan) to record what each short name actually means.
| Pt. Age (yrs)! | SBP/DBP | Diabetes? |
|---|---|---|
| 54 | 140/90 | Yes |
| age_years | sbp_mmhg | diabetes |
|---|---|---|
| 54 | 140 | 1 |
Patient ID Rules
Every dataset needs one column that uniquely identifies each case — never the patient's name, which raises confidentiality concerns and cannot reliably guarantee uniqueness. Use a simple, sequential, de-identified code (e.g., STUDY-001, STUDY-002), assigned once and never reused, even if a patient is later excluded from the analysis.
Keep the master key linking patient identity to study ID in a separate, access-restricted file — never in the same sheet used for statistical analysis.
Numeric vs Text Values, and Handling Dates
Numeric vs Text Values
Keep every numeric variable's column strictly numeric — no units, no symbols, no stray notes typed into the same cells. If a unit needs recording, put it in the column header or the data dictionary, not in individual data cells.
| hemoglobin |
|---|
| 12.4 g/dL |
| 10.1 |
| "low, recheck" |
| hemoglobin_gdl |
|---|
| 12.4 |
| 10.1 |
| 9.8 |
Handling Dates Correctly
Format date columns explicitly as Excel's Date type, and use one consistent, unambiguous format throughout — ISO format (YYYY-MM-DD) is the safest choice, since it sorts correctly and cannot be misread as day-first or month-first by different regional software settings.
| surgery_date |
|---|
| 03/04/2024 |
| 4-Mar-24 |
| 2024.03.05 |
| surgery_date |
|---|
| 2024-03-04 |
| 2024-03-04 |
| 2024-03-05 |
Missing Values
Missing data needs exactly one consistent treatment throughout your entire spreadsheet: either a genuinely blank cell, or one single reserved numeric code (such as -99 or 999) that you then explicitly define as "missing" inside your statistical software before analysis. Mixing several conventions in the same column is one of the most common ways missing data silently corrupts an analysis.
| ldl_mgdl |
|---|
| 112 |
| N/A |
| - |
| unknown |
| ldl_mgdl |
|---|
| 112 |
| 999 |
| 999 |
| 96 |
See our full guide to handling missing data in medical research for the mechanisms and imputation methods that follow once your missing values are cleanly coded.
Coding Categorical Variables
Categorical variables need consistent values throughout their entire column — the same category typed two different ways becomes two different categories to statistical software, even though a human reader would recognize them as identical. See our companion guide on identifying variable types for the full distinction between binary, nominal, and ordinal data before coding anything.
Binary Variables
Code binary (two-category) variables with a single consistent pair of values throughout — numeric 0/1 or 1/2 is the most robust convention, defined with value labels inside your statistical software (0 = No, 1 = Yes).
| sex |
|---|
| Male |
| female |
| M |
| F |
| sex |
|---|
| 1 |
| 2 |
| 1 |
| 2 |
Multi-Category Variables
For variables with three or more categories, assign one numeric code per category and keep the coding scheme identical across every row — document the scheme in your data dictionary so anyone reviewing the file (including your future self) can decode it without guessing.
Resist the temptation to reuse the same numeric codes for different meanings across different variables in the same sheet (using 1/2/3 for disease stage in one column and 1/2/3 for a completely unrelated satisfaction scale in another) without very clear separate documentation — it is a common source of confusion during analysis, particularly months after data entry when the original coding logic is no longer fresh in your memory.
Disease stage: 1 = Stage I, 2 = Stage II, 3 = Stage III, 4 = Stage IV — coded identically for all 200 patients, with the scheme written once in the data dictionary, not re-invented row by row.
Structural Mistakes to Avoid
Avoiding Merged Cells
A merged cell range only actually holds a value in its top-left cell — every other cell in that merged range is empty from the software's point of view. This breaks the one-row-one-case structure and typically produces missing data or a failed import.
| Vital Signs | diabetes | |
|---|---|---|
| sbp | dbp | |
| 140 | 90 | 1 |
| sbp | dbp | diabetes |
|---|---|---|
| 140 | 90 | 1 |
Avoiding Multiple Tables in One Sheet
Keep exactly one data table per sheet, starting at cell A1. A second table placed below or beside the first — even with a blank row or column separating them — is frequently imported as part of the same table, corrupting both.
If you have baseline data and follow-up data, put them in separate sheets (tabs) within the same workbook, or as additional columns in the same wide table — never as two side-by-side blocks on one sheet.
Data Quality Checks Before Analysis
Handling Duplicate Records
Check for duplicate rows using your unique patient ID column, not name, since names can be spelled inconsistently. Excel's Conditional Formatting → Highlight Duplicate Values, or the COUNTIF function, can flag repeated IDs quickly across an entire column.
Patient STUDY-047 appears twice with identical values on every variable — a true accidental duplicate, safe to remove. Patient STUDY-047 appears twice with different visit dates and different lab values — a genuine repeated encounter, which should be kept and distinguished with a separate visit-number column.
Checking Impossible Values
Sort or filter each numeric column and scan its minimum and maximum against what is physiologically or logically possible. This single check, done before analysis, catches a large share of data entry errors in minutes.
| Variable | Plausible Range | Likely Error If Outside |
|---|---|---|
| age | 0–110 years | Negative value; typo (e.g., 540) |
| sbp_mmhg | 60–260 | Value like 1400 (missing decimal) |
| bmi | 10–70 | Value like 250 (height/weight mix-up) |
| likert_item | Within the scale's defined range (e.g., 1–5) | Value of 0 or 6 on a 1–5 scale |
Detecting Outliers Before Analysis
An outlier check in Excel is a quick screening step, not a final decision — flag extreme values with conditional formatting or a simple Z-score formula, then verify each one manually before deciding whether it's a data entry error or a genuine extreme value. Make the final outlier-handling decision inside your statistical software, where it becomes part of your documented, reproducible analysis. See our full guide on outlier detection in medical research for the formal methods that follow this initial screen.
Preparing Data for SPSS, Jamovi, StatClinic, R, and Stata
The core clean-formatting rules above apply identically across every major statistical package — the differences are mostly about column naming strictness and file format.
| Software | Preferred Format | Column Naming Notes |
|---|---|---|
| SPSS | .xlsx or .sav | Short names, no spaces; define value labels and missing codes after import |
| Stata | .xlsx or .dta | No spaces or special characters; variable names are case-sensitive |
| R | .csv or .xlsx | Avoid spaces; names starting with a number will be auto-prefixed |
| Jamovi | .xlsx or .csv | Generally tolerant; still avoid merged cells and mixed types |
| StatClinic | .xlsx or .csv | Upload directly to the Excel Data Cleaning Tool for automatic issue detection before analysis |
If you want an automated first pass rather than checking every rule above by hand, StatClinic's free Excel Data Cleaning Tool scans an uploaded spreadsheet for many of these exact issues — missing value inconsistencies, likely outliers, duplicate rows, and impossible values — and lets you review and fix them before sending the cleaned data straight into a calculator.
Step-by-Step Cleaning Checklist
Confirm one row per patient, one column per variable
No merged cells, no multiple tables on one sheet.
Clean up column headers
Short, lowercase, no spaces or special characters, one variable per header.
Verify a unique, de-identified patient ID column exists
Never the patient's name.
Check every numeric column is purely numeric
No units, symbols, or notes mixed into data cells.
Standardize all date columns to one format
ISO format (YYYY-MM-DD), formatted as a true Date type.
Use one consistent missing-value code throughout
Blank, or a single reserved numeric code — never mixed.
Standardize every categorical variable's coding
One scheme, documented in a data dictionary, applied to every row.
Check for duplicate records
By unique ID, investigated manually before removal.
Run a range check for impossible values
Min/max per column against physiological plausibility.
Flag potential outliers for manual review
Before, not after, opening your statistical software.
Common Reviewer Comments About Poorly Formatted Datasets
"The denominators vary inconsistently across Table 1, suggesting unaddressed missing data or duplicate records."
Inconsistent missing-value coding or unflagged duplicates change the effective sample size differently for different variables, and reviewers notice immediately.
"Please clarify how categorical variables were coded and confirm no data entry inconsistencies exist."
A reviewer who spots implausible category counts (three "types" of a binary variable, for instance) is flagging exactly the inconsistent-coding problem this guide addresses.
"Several values for [variable] appear physiologically implausible; please describe your data quality checks."
An unflagged impossible value that made it into the final analysis signals no range-checking was performed at all.
See our related guide on common reviewer comments about statistics for the broader set of comments reviewers raise beyond data formatting specifically.
Further Reading
- The EQUATOR Network ↗ maintains reporting guidelines (CONSORT, STROBE) that specify how study variables and data handling should be documented and reported.equator-network.org
- The PubMed Central ↗ archive includes numerous methodological papers on clinical data management and quality control practices.ncbi.nlm.nih.gov/pmc
Frequently Asked Questions
Summary
A statistically valid analysis starts long before you open SPSS or R — it starts with a spreadsheet built around one simple structure: one row per patient, one column per cleanly typed variable, no merged cells, no multiple tables, and one consistent code for every missing value and every category. Get this structure right from your very first row of data entry, run a quick duplicate and range check before analysis, and most of the errors a peer reviewer would otherwise catch will never make it into your dataset at all.
Related Articles
Let StatClinic Clean Your Data For You
Upload your Excel file to StatClinic's free Data Cleaning Tool to automatically detect missing values, outliers, duplicates, and formatting issues before you analyze. Free, no registration required.
Try the Data Cleaning Tool →