[英]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_high
, rcpa_b2_pd_low
的均值語句, rcpa_b2_pd_low
段rcpa_b2_pd_high
,rcpa_b2_pd_low分組,則此問題將消失。 但是,我不確定這是否是正確的方法,因為這兩個是比率百分比,不應在group語句中使用。 誰能幫我診斷這個問題? 非常感謝您的投入。
SP
問題出在第一個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中分配隨機名稱
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.