TL;DR

Two SAS tables can become one useful dataset.

Use MERGE with BY to match rows on a shared key such as id.

The setup

Keep the example small and easy to inspect.

Source tablepeople_registry

Personal information such as name, age, weight, and height.

Derived tablepeople_bmi

The shared id plus a calculated BMI value.

Step one

Create the derived table with SET.

1

Start with a clear shared key.

1
ReadUse SET to read people_registry.
2
CalculateCreate bmi from weight and height.
3
KeepOutput id and bmi in people_bmi.
Step two

Sort both datasets by the key before merging.

PROC SORT with BY id puts the observations in the order SAS needs for a reliable match.

Step three

Merge matching observations into one table.

2

Two sources, one enriched result.

1
MergeRead people_registry and people_bmi together.
2
MatchAlign observations with the same id.
3
SaveCreate people_enriched for further analysis.
Watch out

Most beginner errors are about the session, not the syntax.

Missing tableRun the DATA step first

PROC SORT cannot find a dataset that has not been created.

Temporary dataWORK disappears

Datasets in WORK are lost when the SAS session ends.

Shared keyCheck id

Both tables need a usable key for the intended match.

Final takeaway

SET creates the useful pieces. MERGE and BY connect them.

Once the two datasets are sorted by the same key, SAS can turn separate tables into one enriched dataset.