简体   繁体   中英

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

I've tried to run the following code but it gave me an error message. Please see the following.

%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);

And the error message is:

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.

I don't understand where was the mistake. If I remove the mean statements on rcpa_b2_pd_high , rcpa_b2_pd_low , and group by segment, rcpa_b2_pd_high , rcpa_b2_pd_low, then this issue will be gone. However, I'm not sure that's the right methodology since these two are a rate percentage which shouldn't be in the group statement. Could anyone help me diagnose this issue? Your input is greatly appreciated.

SP

The issue is in the first SQL statement.In the first sql statement.

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;

this happens because when an aggregation is done the new aggregated column gets the random name assigned from sas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM