Lesson 16: Combining SAS Data Sets -- Part II

Overview Section

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 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.

Objectives

Upon completion of this lesson, you should be able to:

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
  • explain 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