![]() | ![]() | ![]() | ![]() | ![]() |
Note: Match-merging combines observations from two or more SAS data sets into a single obervation in a new data set according to the values of a common variable. All data sets must be sorted by the variables specified on the BY statement or they must have an index. The number of observations in the new data set is the sum of the largest number of observations in each BY-Group in all data sets.
This is Example 3.3 from Combining and Modifying SAS Data Sets - Examples.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/*******************************************************************************/
/* The objective is to create a new data set that matches each individual with */
/* the correct sale and bonus based on corresponding ID values. This program */
/* match-merges the data sets ONE, TWO, and THREE to create a single data set */
/* that contains variables ID, NAME, SALE, and BONUS. */
/* */
/* Data set TWO contains multiple occurrences of some values of ID, while ONE */
/* and THREE contain only one occurrence. Because values of NAME and BONUS */
/* (which are read from ONE and THREE) are automatically retained across the */
/* BY-group, multiple observations with the same value for ID contain the */
/* correct NAME and BONUS values. */
/*******************************************************************************/
/* Create sample data */
data one;
input id name& $20.;
datalines;
1 Nay Rong
2 Kelly Windsor
3 Julio Meraz
4 Richard Krabill
5 Rita Giuliano
;
data two;
input id sale;
format sale dollar10.;
datalines;
1 28000
2 30000
2 40000
3 15000
3 20000
3 25000
4 35000
5 40000
;
data three;
input id bonus;
format bonus dollar10.;
datalines;
1 2000
2 4000
3 3000
4 2500
5 2800
;
data final;
merge one two three;
by id;
run;
proc print data=final;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Obs id name sale bonus 1 1 Nay Rong $28,000 $2,000 2 2 Kelly Windsor $30,000 $4,000 3 2 Kelly Windsor $40,000 $4,000 4 3 Julio Meraz $15,000 $3,000 5 3 Julio Meraz $20,000 $3,000 6 3 Julio Meraz $25,000 $3,000 7 4 Richard Krabill $35,000 $2,500 8 5 Rita Giuliano $40,000 $2,800
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Statements ==> File-handling ==> MERGE Common Programming Tasks ==> Combining Data SAS Reference ==> Statements ==> File-handling ==> MERGE ==> with BY |
| Date Modified: | 2008-01-28 11:11:41 |
| Date Created: | 2004-09-30 14:09:04 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | All | n/a | n/a |




