Sample 24751: Adding variables from a transaction data set to a master data set based upon a common variable
Produce a new data set by combining variables from a master data
set and a transaction data set based upon a variable common to
both data sets. Include only observations that the master data
set contains.
Note:
Use the MERGE statement with the BY statement to combine the
observations from the two data sets. Use the IN= data set option
to indicate whether the master data set contributed an observation.
The IN= option on the MERGE statement assigns a boolean value to
its variable (in this sample, INMAST). When MERGE is used with a
BY statement, values do not initialize to missing until the BY-Group changes. By resetting the boolean value of INMAST prior to
the MERGE statement, the exact number of observations originally
found in master will appear in COMBINED.
If the INMAST assignment statement is commented out, COMBINED will
have three output observations where FRUIT='pear' instead of one.
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 for a master and transaction data set */
data master;
input fruit $ Y;
datalines;
apple 11
apple 22
apple 33
pear 11
;
data trans;
input fruit $ Z;
datalines;
apple 89
apple 94
apple 83
pear 77
pear 88
pear 99
;
data combined;
inmast=0;
merge master(in=inmast) trans;
by fruit;
if inmast;
run;
proc print data=combined;
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 fruit Y Z
1 apple 11 89
2 apple 22 94
3 apple 33 83
4 pear 11 77
Produce a new data set by combining variables from a master data
set and a transaction data set based upon a variable common to
both data sets. Include only observations that the master data
set contains.
| 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 SAS Reference ==> Statements ==> Information
|
| Date Modified: | 2008-02-28 15:26:01 |
| Date Created: | 2004-09-30 14:09:10 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |