0

我有 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);
4

2 回答 2

3

使用 MPRINT,您应该会看到以下代码:

74   options mprint;
75   %age(AGE1 AGE2 AGE3 AGE4);
MPRINT(AGE):   proc sql;
MPRINT(AGE):   create table segment_test2_ as select distinct T1.* ,T2.FHA as SEG_AGE1 ,T2.FHA as SEG_AGE2 ,T2.FHA as SEG_AGE3
,T2.FHA as SEG_AGE4 from segment_test1 T1 
left join ANNUAL_FH T2 on T1.Model=T2.Model and T1.AGE4=T2.AGE_BT;

注意T1.AGE4=T2.AGE_BT最后。根据您的示例, AGE_BT 必须左对齐并小写以可能等于 AGE4,如下所示:

T1.AGE4=lowcase(left(T2.AGE_BT))
于 2013-10-03T14:58:33.627 回答
0
OPTIONS SYMBOLGEN  MPRINT MLOGIC;
%macro AG;

%LET AA=1;

%do i=0 %to 3;

%let apS = %EVAL(&AA+&i);

proc sql;
create table SEGMENT_&apS as
select distinct T1.*


,T2.Average_FH/12 as  Segment_&aps

from      segment T1
left join FINAL.ANNUAL_FH_AVERAGE T2
on  T1.Model=T2.Model and T1.age&aps=T2.Age_bracket ;
quit;
%end;

%mend AG;
%AG
于 2013-10-04T15:47:21.467 回答