Merging SAS Data Sets |
Excluding Unmatched
Observations |
Selecting Matching Observations
Next, to select only observations that appear in both Clinic.Demog and Clinic.Visit, you specify a subsetting IF statement in the DATA step. |
General form, subsetting IF statement:
where expression is any valid SAS expression.
|
In the DATA step below, the subsetting IF statement checks
the values of InDemog and InVisit and continues
processing only those observations that meet the condition of the expression.
Here the condition is that both Clinic.Demog and
Clinic.Visit contribute to the observation. If the condition
is met, the new observation is written to Clinic.Combined.
Otherwise, the observation is deleted. |
data clinic.combined; merge clinic.demog(in=indemog rename=(date=BirthDate)) clinic.visit(in=invisit rename=(date=VisitDate)); by id; if indemog=1 and invisit=1; run; proc print data=clinic.combined; run; |
In previous examples, Clinic.Combined contained 12 observations. In the output below, notice that only 10 observations met the condition in the IF expression. |
Obs | ID | Age | Sex | BirthDate | Visit | SysBP | DiasBP | Weight | VisitDate |
1 | A001 | 21 | m | 05/22/75 | 1 | 140 | 85 | 195 | 11/05/98 |
2 | A001 | 21 | m | 05/22/75 | 2 | 138 | 90 | 198 | 10/13/98 |
3 | A001 | 21 | m | 05/22/75 | 3 | 145 | 95 | 200 | 07/04/98 |
4 | A002 | 32 | m | 06/15/63 | 1 | 121 | 75 | 168 | 04/14/98 |
5 | A003 | 24 | f | 08/17/72 | 1 | 118 | 68 | 125 | 08/12/98 |
6 | A003 | 24 | f | 08/17/72 | 2 | 112 | 65 | 123 | 08/21/98 |
7 | A004 | . | 03/27/69 | 1 | 143 | 86 | 204 | 03/30/98 | |
8 | A005 | 44 | f | 02/24/52 | 1 | 132 | 76 | 174 | 02/27/98 |
9 | A005 | 44 | f | 02/24/52 | 2 | 132 | 78 | 175 | 07/11/98 |
10 | A005 | 44 | f | 02/24/52 | 3 | 134 | 78 | 176 | 04/16/98 |
SAS software evaluates the expression in an IF statement to produce a result that is either nonzero, zero, or missing. A nonzero and nonmissing result causes the expression to be true; a result of zero or missing causes the expression to be false. So you can specify the subsetting IF statement in the previous example in either of the following ways. The first IF statement checks specifically for a value of 1. The second IF statement checks for a value that is not missing or 0 (which for IN= variables is always 1). if indemog=1 and invisit=1; if indemog and invisit; |
Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.