HOME Module List Site Index About This Site glossary" Resources Innovative Technology Center UT Statistics Courses
Using SAS Choose Design ANOVA Compare Means Regression Examples
Using SAS Using SAS: Table of Contents

Working with SAS datasets
Merging datasets

Merging datasets is used to form a dataset containing all variables (columns). This is only needed if the data from your experiment are in separate files. You could merge them yourself using a spreadsheet program, or have SAS read them separately, then merge them. The other way to combine datasets is to form a dataset containing all observations (rows), using the SET statement.

An example of merging two datasets is shown here, with dataset one and two merged to form M12.

The SAS code for doing this is
MERGE one two; BY student; RUN;

Note that at least one variable must be common to the datasets to be merged, as this serves as a key to "line-up" the observations meaningfully. Actually this is not required if the datasets are known to be in exactly the same order.
DATA M12; MERGE one two; RUN; (no BY statement) would produce the same result in this example, since observations are matched one-to-one.

If both datasets share other variables, like Hwk2, then the values in the dataset listed last in the MERGE statement will overwrite the other dataset, as shown in the example.

More than two datasets can be merged, and SAS simply works from left to right in the MERGE statement, combining variables. For example, MERGE one two tre for; is permitted, and one and two would be merged, then tre would be merged to the result, and then for would be merged. The last merged will overwrite any common variables.


Related Topics:                                                                                                     Using SAS: Table of Contents
 Merging datasets
 Creating new variables
Subsetting the dataset
bullet Miscellaneous

Home | Contact us | Module list & summary | Glossary/Terms | About this site | Stats courses | Links | Index