%macro csbmva_nmltst (input_ds =,output_ds=, flag=); %if &flag = 1 %then %do; data _NULL_; name=put(time(),mmss8.1); name1=kscan(name,1,":."); name2=kscan(name,2,":."); name3=kscan(name,3,":."); name4=ktrim(kleft(name1))||ktrim(kleft(name2))||ktrim(kleft(name3)); call symput('log_name',"&LOG_PATH_CS"||"&sysmacroname"||ktrim(kleft(name4))||".log"); run; proc printto log="&log_name"; run; %end; proc sql; select model_sk,score_time_sk into:model,:time_key from &input_ds ; quit; %let model= &model; %let time_key = &time_key; %let in_lib = %scan(&input_ds,1,%str(.)); %local time_list; %let time_list = .; proc sql noprint; select distinct score_time_sk into :time_list separated by '#' from csbfact._&model._measure_fact where score_time_sk<&time_key and dev_cnt = 0 order by score_time_sk descending; quit; data normal_feed; set &input_ds; run; %let time_list=%sysfunc(ktrim(%sysfunc(kleft(&time_list)))); %if &time_list ne %str(.) %then %do; %let cnt=1; %let token=; %let token=%sysfunc(kscan(&time_list,&cnt,#)); %do %while (&cnt<&CS_NORMAL_SCR_DT and &token ne %str()); %let feed_nm = &in_lib.._&model._&token._pd_pool_fd; proc append base= normal_feed data = &feed_nm force; quit; %let cnt=%eval(&cnt+1); %let token=; %let token=%sysfunc(kscan(&time_list,&cnt,#)); %end; %end; %let err_code=; %csbmva_alldefaults_nodefaults(&input_ds,NO_OF_RECORDS_ACTUAL,No_Of_Actual_Bads, err_code); %if (&err_code ne 'NONE')%then %goto Error_Handler; proc sql noprint; select count(distinct(SCORE_TIME_SK))into :T from normal_feed; quit; %csbmva_errorhandler(err_code); %if (&err_code ne 'NONE')%then %goto Error_Handler; proc sql noprint; select MODEL_TYPE_CD into :model_type from dim.analytical_model_dim inner join &input_ds as b on (analytical_model_dim.model_sk = b.model_sk) ; quit; %put &model_type; proc sql noprint; select measure_sk into:measure_sk from csbdim.measure_dim where MEASURE_CD = "trflgttst"; quit; %put &measure_sk; %let err_code=; proc sql noprint; select bound_green, bound_red into :alphaL, :alphaH from csbridge.Model_type_x_measure where measure_sk = &measure_sk and MODEL_TYPE_CD = "&model_type"; quit; %csbmva_errorhandler(err_code); %if (&err_code ne 'NONE')%then %goto Error_Handler; proc sort data= normal_feed out=work.normal_input; by pool_seq_no; quit; data work.d_normal1; set work.normal_input; diff = (No_Of_Actual_Bads/NO_OF_RECORDS_ACTUAL)-estimated_pd; run; proc sql ; create table work.sumdiff as select sum(diff) as Sumdiff from work.d_normal1 group by Pool_Name ; quit; proc means data=work.d_normal1 std noprint; class pool_seq_no; var diff; output out= work.d_normal2; run; data work.d_normal3; set work.d_normal2; where _stat_ = 'STD' and _type_ ne 0; /* stdev = diff*&T/(&T-1);*/ stdev= diff; run; %csbmva_errorhandler(err_code); %if (&err_code ne 'NONE')%then %goto Error_Handler; /* commented "diff stddev sumdiff" columns to handle incorrect PDF Export. Defect: S1052678, SASNote:52313. FEb'14 */ data &output_ds(keep = NClow NChigh pool_seq_no /* diff stdev sumdiff */ Zcalc Traffic); set work.d_normal3; set work.sumdiff; length traffic 8.; ZCalc =Sumdiff/(Stdev*sqrt(&T)); Nclow =Probit(&alphaL); Nchigh =Probit(&alphaH); if Zcalc = . then Zcalc =0; if Zcalc lt Nclow then traffic = 0; else if Zcalc gt Nchigh then traffic =1; else traffic =2; run; data &output_ds; set &output_ds (rename = (pool_seq_no = pool_seq)); run; %csbmva_errorhandler(err_code); %if (&err_code ne 'NONE')%then %goto Error_Handler; proc printto; run; %return; %Error_Handler: %put ERROR: &err_code; %csbmva_defdata(input_ds=&input_ds,stat='Norm', out_graph_ds =,output_ds =&output_ds ,out_stat_ds=); proc printto; run; %mend csbmva_nmltst;