# Lesson 16: Combining SAS Data Sets -- Part II

## Introduction

In the last lesson, we learned different ways of combining SAS data sets — one-to-one reading, one-to-one merging, concatenating and interleaving. In this lesson, we'll finish up our work in this arena by investigating the process of ** match-merging, **in which we** ** combine two or more SAS data sets based on the values of one or more common variables using MERGE and BY statements. This method deserves its own lesson, because it is far and away the most commonly used method of combining SAS data sets. Once we've learned the how to match-merge two or more SAS data sets, we'll also spend some time exploring how to use DATA step options at the same time that match-merge.

### Learning objectives & outcomes

Upon completing this lesson, you should be able to do the following:

- recognize that SAS data sets must be sorted properly in order to match-merge them
- write code to match-merge data sets that contain the same number of observations, when each observation in the first data set matches with exactly one observation in the second data set
- write code to match-merge data sets that are sorted by the BY variable in descending order
- write code to match-merge data sets that contain a different number of observations, when each observation in the first data set matches with no more than one observation in the second data set
- write code to match-merge data sets that share, aside from the variable that links the data sets together, at least one common variable name
- write code to match-merge data sets when the observations in the first data set to be merged matches one or more observations in the second data set to be merged
- understand how SAS completes a match-merge, and therefore be able to predict the outcome of a match-merge
- use the various DATA step options that are available when match-merging

### Our "to do" list for this lesson

In order to complete the lesson you should:

- Read the lesson pages that follows.
- Type up your answers to the homework problems in a Word file named
**homework16_yourPSUloginid**. If your PSU login id is*xyz123*, then name your file*homework16_xyz123*. - Upload the file to the
**Lesson #16 Homework Dropbox**. - Post any questions or comments you have concerning the lesson's material to the
**Lesson #16 General Discussion Board**. - Take the
**Lesson #16 Mastery Quiz**. Remember two things: i) You have 20 minutes to complete the quiz, and ii) as soon as you hit the "submit" button, your answers are submitted and graded, and the quiz becomes closed to you.