Hi,
Pop2 is a dataset with individuals and their characteristics. lfp is a dataset including parameter from logit regression. For every individual in Pop2, I want to merge parameters corresponding to his characteristics. I have this code in SQL. It works, but it's a bit long and I'd like to reduce it with a macro (it would be also easier to use it if I change the logit model). I'm not really sure what should I do, because the merge is based on different number of variables.
proc sql;
create table pop_lfp1 as
select
p.*,
t1.intercept,
t2.edu_p,
t3.agegr_p,
t4.agegr_edu_p,
t5.young_kid_p,
t6.region_p
from
pop2 p
left join
(
select sex, intercept
from param.lfp
where not missing(intercept)
) t1
on p.sex=t1.sex
left join
(
select sex, edu, edu_p
from param.lfp
where not missing(edu_p)
)t2
on p.sex=t2.sex and p.edu=t2.edu
left join
(
select sex, agegr, agegr_p
from param.lfp
where not missing(agegr_p)
)t3
on p.sex=t3.sex and p.agegr=t3.agegr
left join
(
select sex, agegr, edu, agegr_edu_p
from param.lfp
where not missing(agegr_edu_p)
)t4
on p.sex=t4.sex and p.agegr=t4.agegr and p.edu=t4.edu
left join
(
select sex, young_kid, young_kid_p
from param.lfp
where not missing(young_kid_p)
)t5
on p.sex=t5.sex and p.young_kid=t5.young_kid
left join
(
select sex, region, region_p
from param.lfp
where not missing(region_p)
)t6
on p.sex=t6.sex and p.region=t6.region
;
quit;
... View more