proc sql;
create table 分配后费用汇总表
(
项目 varchar(30),
费用(万元) float format=BESTX20.2
);
quit;
%macro FPH_FY_SUM(col,flt);
proc sql;
connect to teradata(连接TD数据库);
insert into 分配后费用汇总表
select * from connection to teradata
(select &col
,sum(a.CO_Business_Expense_Y2D)/10000
from 明细表 a
inner join 维度表 b
on a.Liab_Center_Id = b.Liab_Center_Id
and a.Data_Dt = b.Data_Dt
where a.Data_Dt = '20160630'
and &flt
group by 1
);
disconnect from teradata;
quit;
%mend FPH_FY_SUM;
data _null_;
set CO_FY_SUM;
call execute('%FPH_FY_SUM('||col_name||','||flt||')');
run;
表CO_FY_SUM的数据如下:
| col_name | flt |
| '营业费用' | 1 = 1 |
| '剔除:境外分行' | substr(b.Liab_Center_Type,2,2) = '03' |
| '境外分行-香港分行' | substr(b.Liab_Center_Id,1,4) = '9985' |
| '境外分行-香港代表处' | b.Liab_Center_Id = '9901320000' |
| '境外分行-新加坡筹' | b.Liab_Center_Type = 'F03702' |
| '剔除:总行信用卡' | substr(b.Liab_Center_Id,1,4) = '9911' |
| '剔除:总行奖福金' | substr(b.Liab_Center_Type,2,2) = '02' |
| '各板块费用' | substr(b.Liab_Center_Type,2,2) not in ('02','03','') |
| '公司管理' | substr(b.Liab_Center_Type,2,2) = '10' |
| '公司营销' | substr(b.Liab_Center_Type,2,2) = '11' |
| '零售管理' | substr(b.Liab_Center_Type,2,2) = '30' |
| '零售营销' | substr(b.Liab_Center_Type,2,2) = '31' |
| '资金管理' | substr(b.Liab_Center_Type,2,2) = '50' |
| '资金营销' | substr(b.Liab_Center_Type,2,2) = '51' |
| '其他板块' | substr(b.Liab_Center_Type,2,2) in ('62','63','64','65','72','73','74','75','76','77','79') |
| '各板块费用' | substr(b.Liab_Center_Type,2,2) not in ('02','03','') |
| '总行费用' | substr(b.Liab_Center_Type,2,2) not in ('02','03','') and substr(b.Liab_Center_Type,1,1)='Z' |
| '分行费用' | substr(b.Liab_Center_Type,2,2) not in ('02','03','') and substr(b.Liab_Center_Type,1,1)='F' |
| '异地行费用' | substr(b.Liab_Center_Type,2,2) not in ('02','03','') and substr(b.Liab_Center_Type,1,1)='Y' |
| '支行费用' | substr(b.Liab_Center_Type,2,2) not in ('02','03','') and substr(b.Liab_Center_Type,1,1)='W' |
反正就是第一个是字段名,第二个是相应的过滤条件。
最后结果,只插入了下面这些数据
| 境外分行-香港分行 |
| 剔除:总行奖福金 |
| 各板块费用 |
| 公司管理 |
| 公司营销 |
| 零售管理 |
| 零售营销 |
| 资金管理 |
| 资金营销 |
| 其他板块 |
| 各板块费用 |
| 总行费用 |
| 分行费用 |
| 异地行费用 |
| 支行费用 |
没插入的数据报错都是提示 无效的宏参数名