Sample 24677: One-to-many or many-to-one merge
Combine two data sets by common variables when there are
duplicates in only one data set.
Note:
When SAS reads the last observation from a BY-Group in one data
set, SAS retains its values in the program data vector for all
variables that are unique to that data set until all observations
for that BY-Group have been read from all data sets.
The total number of observations in the final data set is the
sum of the maximum number of observations in a BY-Group from
either data set.
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.
/* Create sample data */
data one;
input id $ fruit $;
datalines;
a apple
a apple
b banana
c coconut
;
data two;
input id $ color $;
datalines;
a amber
b brown
c cream
c cocoa
c carmel
;
data both;
merge one two;
by id;
run;
proc print data=both;
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 fruit color
1 a apple amber
2 a apple amber
3 b banana brown
4 c coconut cream
5 c coconut cocoa
6 c coconut carmel
Combine two data sets by common variables when there are
duplicates in only one data set.
| 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-02-21 11:18:45 |
| Date Created: | 2004-09-30 14:09:03 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |