O'Reilly logo

Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition by SAS Institute

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 19
Merging SAS Data Sets
Introduction to Merging SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Understanding the MERGE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
One-to-One Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Definition of One-to-One Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Performing a Simple One-to-One Merge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Performing a One-to-One Merge on Data Sets with the Same Variables . . . . . . . . 293
Match-Merging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Merging with a BY Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
The Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Explanation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Match-Merging Data Sets with Multiple Observations in a BY Group . . . . . . . . . 300
Match-Merging Data Sets with Dropped Variables . . . . . . . . . . . . . . . . . . . . . . . . 305
Match-Merging Data Sets with the IN= Data Set Option . . . . . . . . . . . . . . . . . . . . 307
Match-Merging Data Sets with the Same Variables . . . . . . . . . . . . . . . . . . . . . . . . 308
Match-Merging Data Sets That Lack a Common Variable . . . . . . . . . . . . . . . . . . . 308
Choosing between One-to-One Merging and Match-Merging . . . . . . . . . . . . . . . . 310
Comparing Match-Merge Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
When to Use a One-to-One Merge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
When to Use a Match-Merge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
Introduction to Merging SAS Data Sets
Purpose
Merging combines observations from two or more SAS data sets into a single
observation in a new SAS data set. The new data set contains all variables from all the
original data sets unless you specify otherwise.
289

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required