我有 2 个表,我想通过与 T1 的 MODEL 和 AGE 与 T2 的 MODEL 和 AGE_BT 匹配来输出。我已经使用了代码并且得到了空白输出。输出应如下面的输出表所示。.
Table:1
MODEL AGE1 AGE2 AGE3 AGE4
SLOT1 0-10 10-20 20-35 35p
SLOT1 0-10 10-20 20-35 35p
SLOT1 0-10 10-20 20-35 35p
SLOT2 0-10 10-20 20-35 35p
SLOT2 0-10 10-20 20-35 35p
SLOT3 0-10 10-20 20-35 35p
Table:2
MODEL AGE_BT FHA
SLOT1 0-10 600
SLOT1 10-20 435
SLOT1 20-35 210
SLOT1 35P 10
SLOT2 0-10 391
SLOT2 10-20 385
SLOT2 20-35 246
SLOT2 35P 0
SLOT3 0-10 391
SLOT3 10-20 385
SLOT3 20-35 246
SLOT3 35P 0
OUTPUT TABLE
MODEL AGE1 AGE2 AGE3 AGE4 SEG_AGE1 SEG_AGE2 SEG_AGE3 SEG_AGE4
SLOT1 0-10 10-20 20-35 35p 600 435 210 10
SLOT1 0-10 10-20 20-35 35p 600 435 210 10
SLOT1 0-10 10-20 20-35 35p 600 435 210 10
SLOT1 0-10 10-20 20-35 35p 600 435 210 10
SLOT1 0-10 10-20 20-35 35p 600 435 210 10
SLOT1 0-10 10-20 20-35 35p 600 435 210 10
SLOT2 0-10 10-20 20-35 35p 391 385 246 0
SLOT2 0-10 10-20 20-35 35p 391 385 246 0
SLOT2 0-10 10-20 20-35 35p 391 385 246 0
SLOT2 0-10 10-20 20-35 35p 391 385 246 0
%macro age(ageap);
%let n=%sysfunc(countw(&ageap));
proc sql;
create table segment_test2_ as
select distinct T1.*
%do i=1 %to &n;
%let ap = %scan(&ageap,&i);
,T2.FHA as SEG_&ap
%end;
from segment_test1 T1
left join ANNUAL_FH T2
on T1.Model=T2.Model and T1.&ap=T2.AGE_BT;
quit;
%mend;
%age(AGE1 AGE2 AGE3 AGE4);