Match-Merging

Overview

So far in this chapter, we've combined data sets based on the order of the observations in the input data sets. But sometimes you need to combine observations from two or more data sets into a single observation in a new data set according to the values of a common variable. This is called match-merging.
When you match-merge, you use a MERGE statement rather than a SET statement to combine data sets.
General form, basic DATA step for match-merging:
DATA output-SAS-data-set;
MERGE SAS-data-set-1 SAS-data-set-2;
BY <DESCENDING> variable(s);
RUN;
where
  • output-SAS-data-set names the data set to be created.
  • SAS-data-set-1 and SAS-data-set-2 specify the data sets to be read.
  • variable(s) in the BY ...

Get SAS Certification Prep Guide: Base Programming for SAS 9, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.