Merging SAS Data Sets |
Renaming
Variables |
Sometimes you may have variables with the same name in more
than one input data set. In this case, DATA step match-merging
overwrites values of the like-named variable in the first
data set in which it appears with values of the like-named variable in subsequent
data sets.
For example, Clinic.Demog contains the variable
data clinic.combined; merge clinic.demog clinic.visit; by id; run; proc print data=clinic.combined; run; The following output shows the effects of overwriting variable values in the Clinic.Combined data set. In most observations, the date is now the date of the clinic visit. In observation 11, the date is still the birth date because the value for the date of the clinic visit is missing. |
Obs | ID | Age | Sex | Date | Visit | SysBP | DiasBP | Weight |
1 | A001 | 21 | m | 11/05/98 | 1 | 140 | 85 | 195 |
2 | A001 | 21 | m | 10/13/98 | 2 | 138 | 90 | 198 |
3 | A001 | 21 | m | 07/04/98 | 3 | 145 | 95 | 200 |
4 | A002 | 32 | m | 04/14/98 | 1 | 121 | 75 | 168 |
5 | A003 | 24 | f | 08/12/98 | 1 | 118 | 68 | 125 |
6 | A003 | 24 | f | 08/21/98 | 2 | 112 | 65 | 123 |
7 | A004 | . | 03/30/98 | 1 | 143 | 86 | 204 | |
8 | A005 | 44 | f | 02/27/98 | 1 | 132 | 76 | 174 |
9 | A005 | 44 | f | 07/11/98 | 2 | 132 | 78 | 175 |
10 | A005 | 44 | f | 04/16/98 | 3 | 134 | 78 | 176 |
11 | A007 | 39 | m | 11/11/57 | . | . | . | |
12 | A008 | . | 05/22/98 | 1 | 126 | 80 | 182 |
Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.