Sample 24680: Merge multiple data sets and output matches only
Use the IN= option to determine if a data set
contributes to the BY-Group. Output if the BY-Group is
found in all data sets.
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 three sample data sets */
data file1;
input var name $;
datalines;
100 Anja
200 Bob
400 Chandra
600 Darrin
;
data file2;
infile datalines dsd truncover;
input var address $ 13.;
datalines;
100,34 Smith Road
200,67 Burt Ave
300,12 You St
400,45 Younge St
500,79 Wellington
600,23 Done Road
;
data file3;
input var zip;
datalines;
100 28092
200 27502
300 27539
600 27526
;
/* The IN= variable is a boolean flag that resets when a BY-Group */
/* changes. To output only matches from the MERGE, test for the */
/* condition that the current BY-Group is found in all data sets. */
/* */
/* Sample data is already in sorted order by VAR, so no sorting */
/* is needed. */
data three;
merge file1 (in=a) file2 (in=b) file3 (in=c);
by var;
if a and b and c;
run;
proc print data=three;
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 var name address zip
1 100 Anja 34 Smith Road 28092
2 200 Bob 67 Burt Ave 27502
3 600 Darrin 23 Done Road 27526
Use the IN= option to determine if a data set
contributes to the BY group. Output if BY group is
found in all data sets.
| 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 IN= Common Programming Tasks ==> Selecting Data
|
| Date Modified: | 2008-01-28 11:08:08 |
| Date Created: | 2004-09-30 14:09:03 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |