StatDataViewer Logo

PROC COMPARE Without SAS: Dataset Comparison in StatDataViewer

Dataset comparison is one of the most common tasks in clinical programming: compare the current delivery of ADSL against the previous one, verify that a dataset re-run produced identical results, or check whether a data amendment touched anything unexpected. The standard SAS tool for this is PROC COMPARE — powerful, but it requires a SAS session, a log to read, and a bit of boilerplate code every time.

StatDataViewer's Compare tool provides the same output interactively, without SAS. This post explains how to use it effectively and where it differs from PROC COMPARE.

What PROC COMPARE does — and what we're replicating

PROC COMPARE matches rows between two datasets using one or more ID variables, then reports:

  • Rows in the base dataset but not the compare dataset (and vice versa).
  • For matched rows: which variables have different values, and what those values are.

That is exactly what StatDataViewer's Compare tool produces — the key difference is that the results are presented as an interactive table you can sort, filter, and drill into, rather than a text log.

Setting up a comparison

Open Tools → Compare Datasets. The first row of the window holds everything a comparison needs:

1. Base

Pick the reference file: typically the previous version, the production dataset, or the expected output. Any supported format works, so a SAS dataset can be compared with an .xpt, an R .rds or a CSV.

2. Comp

Pick the dataset you want to compare against the base: typically the new delivery, the re-run output, or the amended version. Both files are read in the background as soon as they are chosen.

The base and compare datasets do not need to be in the same library. Add PREV_DELIVERY and CURRENT_DELIVERY as separate libraries and pick across them, or choose the two files in the Workspace's two panels and click Compare there.

3. ID variables

The variables that identify a row. For most ADaM datasets this is STUDYID USUBJID or STUDYID USUBJID ASEQ; for SDTM, STUDYID USUBJID AESEQ for AE, or STUDYID USUBJID LBTESTCD LBDTC for LB.

The window suggests a key from the CDISC naming (subject, parameter, visit, sequence) and checks it: a tick on the ID button means every row has a key of its own in both datasets, a warning sign means duplicate keys, and the tooltip says how many. Click the button to open Select ID Variables and change the list. With no ID variables, rows are matched by position.

4. Variables

Before the comparison runs, the Variables view lists the variables of both datasets side by side with their type, length, format and label, so structural differences show before any value is compared. All common variables are compared; the toolbar filters what you see afterwards.

Reading the results

After clicking Compare, the window switches to the Observations view: three panes scrolled together.

ID, Base and Comp panes

The ID variables are on the left, the base values in the middle and the compare values on the right, in key order. Cells that differ are highlighted, and the variables with differences come first. The status line counts the rows of each kind: base, comp, matched, equal, different, base-only, comp-only.

Rows and variables by kind

The toolbar's Observations kinds show or hide the rows whose values are equal, the rows whose values differ, the rows only the base has and the rows only the compare has. Equal rows are hidden automatically after a compare, so the differences are what you see first. The Variables kinds do the same for the attributes (equal, different, base only, compare only), and Columns ≠ / = keeps only the variables whose values differ in the rows shown. Common causes of base-only and comp-only rows:

  • Subjects added or dropped between deliveries.
  • New AE or CM records in an amendment.
  • ID variable discrepancies (e.g. trailing spaces, case differences).

Walking the differences

Prev and Next (keys P and N) step through the differences one by one. Press F on a column for a Base / Comp frequency of its values over the rows shown, with the counts that differ marked; press Ctrl+L to go to a row number or a key value.

Filtering inside the comparison

The Filter box takes a SAS expression and keeps a row when either side matches it: USUBJID = "01-701-1015" or AVISITN >= 4. The same keys as in a data window build it from a cell: D for this value, I for the selected values, ^ for not this value, C to clear and Z to undo one step. A scoped review, say only the adverse events of treatment arm A, is one keystroke on an arm cell.

Options sets how values are compared: ignore case in text, treat blanks as missing, and a numeric tolerance for values that differ only by floating-point noise. Report writes a PROC COMPARE report in SAS's own layout that can be filed with the validation.

How it differs from PROC COMPARE

Feature PROC COMPARE StatDataViewer Compare
Requires SAS license Yes No
Output format Log / ODS output dataset Interactive table (sortable, filterable)
Numeric tolerance (CRITERION=) Yes Yes (Options → Numeric tolerance)
Cross-library comparison Requires LIBNAME statements Point-and-click
Filter before compare WHERE= option in dataset options Filter box in the window, or one key on a cell
Time to run Write code → submit → read log Pick two files → Compare → results in under a second

For most day-to-day comparison tasks in clinical programming, StatDataViewer's Compare tool is faster, and the PROC COMPARE report it writes keeps the validation file in the format reviewers expect. PROC COMPARE itself remains the choice when the comparison must run inside a batch validation pipeline.

Try it now

The Compare tool is available in the free version — no license required. See the Compare datasets documentation for the complete reference, or try StatDataViewer in your browser with sample data right now.

Download StatDataViewer — it's free →