You have two ways to do it:
1. Use 'case' function to create a new variable, 'case' is really similar like 'if ... then' in your datastep.
2. Use 'coalesce' with OUTER JOINS (full join, left join, right join) operations:
coalesce (a.id, 0) will change all missing values or unmatched values of a.id as 0.
coalesce (b.id, 9999) will change all unmatched or missing value of b.id as 9999.
data a;
input
id age; cards
; 3 12
4 5
5 35
6 20
7 11
8 20
;
run
; data
b; input
id gender $; cards
; 1 F
2 M
4 M
6 F
7 M
10 F
11 M
;
run
; ***METHOD 1****;
proc sql;
select
a.*, b.gender, case when a.id>0 then 1 else 0 end as ina, case when b.id>0 then 1 else 0 end as inb from
a full join b on a.id=b.id;
quit
; ***MATHOD 2****;
proc
sql; select
a.*, b.gender, coalesce(a.id, 0) as ina, coalesce (b.id,9999) as inb from
a full join b on a.id=b.id;
quit
; [此贴子已经被作者于2007-2-23 5:33:31编辑过]