SAS 中 Proc sql 中的这段代码有什么问题

What's wrong with this code in Proc sql in SAS

我已经尝试 运行 以下代码,但它给了我一条错误消息。请看下面

%macro bktest(prod=);
proc sql;
create table &prod._pd_coh_seg as   
select distinct
ASOF_YYYYMM,
segment,
mean(rcpa_b2_pd_low),
mean(rcpa_b2_pd_high),
sum(rcpa_weight) as Count,
sum(annual_default_occurrence*rcpa_weight)/sum(rcpa_weight) as dr_ct,
sum(dp_pit*rcpa_weight)/sum(rcpa_weight) as pd_ct_pit,
sum(RCPA_B2_PD_TTC_SEG_FCTR*rcpa_weight)/sum(rcpa_weight) as pd_ct_ttc
from backtest.&prod._final
group by segment;
quit;

data &prod._pd_coh_seg;
set &prod._pd_coh_seg;
abs_diff_pit=abs(dr_ct-pd_ct_pit);
abs_diff_ttc=abs(dr_ct-pd_ct_ttc);
run;

proc sort data =&prod._pd_coh_seg;
by ASOF_YYYYMM segment;
quit;

proc sql;
create table &prod._pd_mad_rov as   
select distinct
segment,
mean(rcpa_b2_pd_low),
mean(rcpa_b2_pd_high),
count(*) as Count,
sum(abs_diff_pit)/count(abs_diff_pit) as mad_pit,
sum(abs_diff_ttc)/count(abs_diff_ttc) as mad_ttc,
sum(order)/count(abs_diff_pit) as breaks
from &prod._pd_coh_seg
group by segment;
quit;

%mend;

%bktest(prod=auto);
%bktest(prod=cred);
%bktest(prod=manu);
%bktest(prod=spec);

%macro bktest(prod=);
PROC EXPORT DATA= &prod._pd_mad_rov
            OUTFILE= "/ecm_dr/retail/other/zkt0jqm/2014Q3/pd_mad_rov.xlsx" 
            DBMS=XLSX REPLACE;
     SHEET="&prod."; 
RUN;
%mend;

%bktest(prod=auto);
%bktest(prod=spec);
%bktest(prod=manu);
%bktest(prod=cred);

错误信息是:

ERROR: The MEAN summary function requires a numeric argument.
ERROR: The MEAN summary function requires a numeric argument.
ERROR: The following columns were not found in the contributing tables: rcpa_b2_pd_high, rcpa_b2_pd_low.

我不明白哪里错了。如果我删除 rcpa_b2_pd_highrcpa_b2_pd_low 和分组 rcpa_b2_pd_high、rcpa_b2_pd_low 上的均值语句,那么这个问题就会消失。但是,我不确定这是正确的方法,因为这两个是不应该出现在集团声明中的利率百分比。 谁能帮我诊断这个问题?非常感谢您的意见。

SP

问题出在第一个 SQL statement.In 第一个 sql 语句中。

proc sql;

create table &prod._pd_coh_seg as   
select distinct
ASOF_YYYYMM,
segment,
mean(rcpa_b2_pd_low) as rcpa_b2_pd_low,
mean(rcpa_b2_pd_high) as rcpa_b2_pd_high,
sum(rcpa_weight) as Count,
sum(annual_default_occurrence*rcpa_weight)/sum(rcpa_weight) as dr_ct,
sum(dp_pit*rcpa_weight)/sum(rcpa_weight) as pd_ct_pit,
sum(RCPA_B2_PD_TTC_SEG_FCTR*rcpa_weight)/sum(rcpa_weight) as pd_ct_ttc
from backtest.&prod._final
group by segment;
quit;

发生这种情况是因为当聚合完成时,新聚合列获得从 sas 分配的随机名称