Merging SAS Data Sets |
Preparing Data for
Match-Merging |
Sorting Data
If your data is not appropriately sorted or indexed, you can use the SORT procedure before match-merging. You can sort the existing data set permanently or create a separate, sorted output data set. |
General form, simple PROC SORT step:
where
|
In the PROC SORT steps below, the two data sets are sorted
by the common variable ID so that data is merged correctly
for each patient.
proc sort data=clinic.demog; by id; run; proc sort data=clinic.visit; by id; run; proc print data=clinic.demog; run; proc print data=clinic.visit; run; |
Obs | ID | Age | Sex | Date |
1 | A001 | 21 | m | 05/22/75 |
2 | A002 | 32 | m | 06/15/63 |
3 | A003 | 24 | f | 08/17/72 |
4 | A004 | . | 03/27/69 | |
5 | A005 | 44 | f | 02/24/52 |
6 | A007 | 39 | m | 11/11/57 |
Obs | ID | Visit | SysBP | DiasBP | Weight | Date |
1 | A001 | 1 | 140 | 85 | 195 | 11/05/98 |
2 | A001 | 2 | 138 | 90 | 198 | 10/13/98 |
3 | A001 | 3 | 145 | 95 | 200 | 07/04/98 |
4 | A002 | 1 | 121 | 75 | 168 | 04/14/98 |
5 | A003 | 1 | 118 | 68 | 125 | 08/12/98 |
6 | A003 | 2 | 112 | 65 | 123 | 08/21/98 |
7 | A004 | 1 | 143 | 86 | 204 | 03/30/98 |
8 | A005 | 1 | 132 | 76 | 174 | 02/27/98 |
9 | A005 | 2 | 132 | 78 | 175 | 07/11/98 |
10 | A005 | 3 | 134 | 78 | 176 | 04/16/98 |
11 | A008 | 1 | 126 | 80 | 182 | 05/22/98 |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.