Working with SAS 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
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.
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.