Merging SAS Data Sets |
Selecting
Variables |
In addition to selecting observations, you can select variables to appear in your output data set. You name the variables you want to drop or keep using the DROP= and KEEP= data set options. You can use the KEEP= option instead of the DROP= option if more variables are dropped than kept. |
General form, DROP= and KEEP= data set
options:
where
|
For example, the DATA step below reads all variables from
Clinic.Demog and all variables except Weight
from Clinic.Visit, and then excludes the variable
ID from Clinic.Combined after the merge
processing is complete. |
data clinic.combined(drop=id); merge clinic.demog(in=InDemog rename=(date=BirthDate)) clinic.visit(drop=weight in=InVisit); by id; if indemog and invisit; run; proc print data=clinic.combined; run; |
Obs | Age | Sex | BirthDate | Visit | SysBP | DiasBP | VisitDate |
1 | 21 | m | 05/22/75 | 1 | 140 | 85 | 11/05/98 |
2 | 21 | m | 05/22/75 | 2 | 138 | 90 | 10/13/98 |
3 | 21 | m | 05/22/75 | 3 | 145 | 95 | 07/04/98 |
4 | 32 | m | 06/15/63 | 1 | 121 | 75 | 04/14/98 |
5 | 24 | f | 08/17/72 | 1 | 118 | 68 | 08/12/98 |
6 | 24 | f | 08/17/72 | 2 | 112 | 65 | 08/21/98 |
7 | . | 03/27/69 | 1 | 143 | 86 | 03/30/98 | |
8 | 44 | f | 02/24/52 | 1 | 132 | 76 | 02/27/98 |
9 | 44 | f | 02/24/52 | 2 | 132 | 78 | 07/11/98 |
10 | 44 | f | 02/24/52 | 3 | 134 | 78 | 04/16/98 |
Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.