30%macro run_postcode_ccar_provision;
50 %let ds_out_migration_detail = ST_STG.MIGRATION_DETAIL;
53 %
if (%upcase(&query_all_hrz_flg.) eq Y) %then %
do;
54 %let queryIndex = %str( );
56 %
else %
if (%upcase(&keep_cube_flg.) eq Y) %then %
do;
57 %let queryIndex = BASECASE &curr_mipHorizon.;
60 %let queryIndex = BASECASE 1;
66 %let bep_keep = bepName;
67 %let bep_lookup = ,
"&bep_keep.";
68 %let bep_csv = , &bep_keep.;
69 %let query_weight_vars_dma=;
72 %
if(&scen_weight_flg. = Y) %then %
do;
73 %let weight_keep = defaultWeight;
74 %let weight_lookup = ,
"&weight_keep.";
75 %let weight_csv = , &weight_keep.;
77 %let query_weight_vars=&query_weight_vars. el_amt;
78 %let query_weight_vars_dma=&query_weight_vars. initial_risk_rating;
82 %let mip_query_custom_code = %str(
90 scenarioId = scenario_id
91 forecastTime = forecast_time
95 set &ds_in_scen_info.(keep = forecastTime &bep_keep mrsName &weight_keep.);
99 declare hash hScen(dataset:
"&ds_in_scen_info.");
100 hScen.defineKey(
"scenarioId");
101 hScen.defineData(
"forecastTime" &bep_lookup.,
"mrsName" &weight_lookup.);
107 call missing(forecastTime &bep_csv., mrsName &weight_csv.);
108 __rc__ = hScen.find();
110 scenario_name = catx(
" - " &bep_csv., mrsName);
111 forecastTime = sum(forecastTime, 0);
112 forecast_period = catx(
" ",
"&mipinterval.", put(forecastTime, 8.));
116 %
if &dma_expansion_flg eq Y %then %
do;
117 %let dma_expanded_portfolio = &ds_in_portfolio;
118 %let crossclassvars = original_instid;
119 %let instid_rename_stmt = (rename = (original_instid = instid));
121 %let ds_in_portfolio = work.portfolio_orig_&base_dt_ymdn._&model_run_key.;
122 %irm_rgf_retrieve_analysis_data(key = &data_prep_out_portfolio_key.
123 , libref = &dr_libref.
124 , dr_library_name = &dr_library_name.
125 , outds = &ds_in_portfolio
126 , outds_partition_list = ptf_partition_list
128 , outds_dataInfo = portfolio_dataInfo
129 , outds_dataDef = portfolio_dataDef
130 , host = &rgf_protocol.:
131 , server = &rgf_service.
132 , solution = &rgf_solution.
134 , tgt_ticket = &tgt_ticket.
135 , outVarTicket = ticket
136 , outSuccess = httpSuccess
137 , outResponseStatus = responseStatus
142 %
if %sysevalf(%superq(cpty_rename_stmt) ne,
boolean) %then
144 proc datasets library=work;
145 modify portfolio_orig_&base_dt_ymdn._&model_run_key.;
146 rename &cpty_rename_stmt.;
152 %let crossclassvars = instid;
153 %let instid_rename_stmt = %str();
157 %irm_query_mip_results(conf_lib = mipconf
158 , expprojlib = mipexp
159 , out_ds = tmp_model_result_&run_idx.&instid_rename_stmt / view = tmp_model_result_&run_idx.
160 , out_ds_type = &mip_query_output_type.
161 , run_instance = &mip_runInstance_name.
162 , workgroup = &mip_ms_workgroup.
163 , where_clause = &mipQueryFilter.
164 , keep_vars = &query_weight_vars.
165 , horizon_index = &queryIndex.
166 , crossclassvars = &crossclassvars
167 , mip_root = &mip_root.
168 , enrich_output_flg = Y
169 , out_scenario_var = scenarioId
170 , scenario_id_value = &scenario_id_value.
171 , out_asofdate_var = base_dt
172 , custom_code = %superq(mip_query_custom_code)
173 , tmp_ds_suffix = &run_idx.
176 %let hResult_ds = tmp_model_result_&run_idx.;
177 %
if(&scen_weight_flg. = Y) %then %
do;
179 %let hResult_ds = tmp_model_result_all_&run_idx.;
182 proc summary data = tmp_model_result_&run_idx. missing nway;
183 class base_dt horizon forecast_time forecast_period &bep_keep instid;
184 var &query_weight_vars.;
185 weight &weight_keep.;
187 out = tmp_model_result_weighted_&run_idx. (drop = _type_ _freq_)
192 data tmp_model_result_all_&run_idx. / view = tmp_model_result_all_&run_idx.;
194 tmp_model_result_&run_idx.
195 tmp_model_result_weighted_&run_idx. (in = __weighted__)
198 if __weighted__ then
do;
199 mrsName =
"Weighted";
200 scenario_name = catx(
" - " &bep_csv., mrsName);
201 scenario_id = catx(
"_" &bep_csv., mrsName, cats(
"FT", sum(forecastTime, 0)));
202 if horizon ne 0 then output;
209 %let result_var_list = %sysfunc(prxchange(s/\bINSTID\b
210 %let result_var_list_csv = %sysfunc(prxchange(s/\s+/%str(, )/i, -1, &result_var_list.));
213 data &ds_in_model_result. / view = &ds_in_model_result.;
214 set &ds_in_portfolio.
215 %
if(%sysevalf(%superq(cpty_reverse_rename_stmt) ne,
boolean)) %then %
do;
216 (rename = (&cpty_reverse_rename_stmt.))
221 length MOVEMENT_ID 8. MOVEMENT_DESC $100.;
224 MOVEMENT_DESC
"01. Model Output"
228 activationScenario = activation_scenario
229 activationHorizon = activation_horizon
236 declare hash hResult(dataset:
"&hResult_ds.", multidata:
"yes");
237 hResult.defineKey(
"instid");
238 hResult.defineData(all:
"yes");
239 hResult.defineDone();
243 call missing(&result_var_list_csv.);
244 __rc__ = hResult.find();
246 if (__rc__ = 0) then
do;
248 do while(__rc__ = 0);
250 %
if &dma_expansion_flg eq Y %then
251 synthetic_instrument_flg =
'N';;
253 %
if(&scen_weight_flg. = Y) %then
254 if mrsName=
"Weighted" then evaldate=intnx(
"&mipInterval.", reporting_dt, horizon,
"SAME");;
257 if(synthetic_instrument_flg =
"N" or activationScenario = scenario_id) then
261 call missing(&result_var_list_csv.);
262 __rc__ = hResult.find_next();
275 %let libref = %scan(&ds_out_migration_detail., 1, .);
277 %include
"&fa_path./source/sas/misc/ddl/reportmart/%lowcase(%scan(&ds_out_migration_detail., 2, .)).sas" / source2 lrecl = 32000;
287 data work.tmp_model_result_1;
288 set &ds_in_model_result
289 %
if %rsk_varexist(&ds_in_model_result, initial_risk_rating) %then
291 (drop = initial_risk_rating)
297 if not missing(scenario_name) then
298 scenario_name = strip(substr(scenario_name, find(scenario_name,
"-")+1));
300 else if horizon eq 0 then
301 scenario_name =
"Actual";
307 data work.htbl_basecase_el (rename = (el_amt = basecase_el));
308 set work.tmp_model_result_1 (keep = instid
318 data work.tmp_model_result_2 (drop = rc);
319 set work.tmp_model_result_1;
320 call missing(basecase_el);
324 %irm_build_hash_lookup(
325 hash_name = h_basecase_el,
326 hash_table = work.htbl_basecase_el,
328 data_vars = basecase_el
331 rc = h_basecase_el.find();
339 select distinct scenario_id,
343 from work.tmp_model_result_1
346 %let scen_cnt = &sqlobs;
351 data &ds_out_model_result;
352 set work.tmp_model_result_2;
355 %
do i=1 %to &scen_cnt;
356 scenario_id =
"&&scen_id_&i";
357 scenario_name =
"&&scen_nm_&i";
361 else if horizon gt 0 then
369 %global drop_statement;
370 %
if %qupcase(&dma_expansion_flg) ne Y %then
373 %let crossclassvars = instid;
377 %let filter = (&mipQueryFilter.) and dma_expansion_flag eq
'Y';
378 %let crossclassvars = instid dma_expansion_flag;
379 %let drop_statement = (drop = dma_expansion_flag);
385 %irm_query_mip_results(
388 out_ds = tmp_model_result_dma_&run_idx.&drop_statement / view = tmp_model_result_dma_&run_idx.,
389 out_ds_type = &mip_query_output_type.,
390 run_instance = &mip_runInstance_name.,
391 workgroup = &mip_ms_workgroup.,
392 where_clause = &filter,
393 keep_vars = &query_weight_vars_dma.,
394 horizon_index = &queryIndex.,
395 crossclassvars = &crossclassvars,
396 mip_root = &mip_root.,
397 enrich_output_flg = Y,
398 out_scenario_var = scenarioId,
399 scenario_id_value = &scenario_id_value.,
400 out_asofdate_var = base_dt,
401 custom_code = %superq(mip_query_custom_code),
402 tmp_ds_suffix = dma_&run_idx.
405 %let hResult_ds_dma = tmp_model_result_dma_&run_idx.;
407 %
if(&scen_weight_flg. eq Y) %then
409 %let hResult_ds_dma = tmp_model_result_dma_all_&run_idx;
410 %irmst_weight_mip_results(
411 outds = tmp_model_result_dma_all_&run_idx. / view = tmp_model_result_dma_all_&run_idx.,
412 in_mip_result_ds = tmp_model_result_dma_&run_idx.,
413 class_vars = &bep_keep,
414 output_vars = &query_weight_vars_dma.,
415 weight_vars = &weight_keep.,
416 scenario_vars = %quote(&bep_csv)
420 %irmst_enrich_mip_results(
421 outds = work.migration_results,
422 in_mip_result_ds = &hResult_ds_dma,
423 in_mip_portfolio_ds = %
if %qupcase(&dma_expansion_flg.) eq Y %then
424 &dma_expanded_portfolio,;
427 reverse_rename_stmt = &cpty_reverse_rename_stmt,
437 select distinct cats(
439 strip(substr(instid, find(instid,
"_", -length(instid))+1)),
440 ') initial_risk_rating = "',
443 ) into :rating_list separated by ' '
444 from work.migration_results
445 where upcase(rating_agency) eq 'S&P';
452 data &ds_out_migration_detail. (keep = %rsk_getvarlist(&ds_out_migration_detail.));
458 set &ds_out_migration_detail;
460 set work.migration_results (rename = (initial_risk_rating = initial_risk_rating_num));
461 where upcase(rating_agency) eq 'S&P';
463 %if(&scen_weight_flg. = Y) %then
464 if mrsName="Weighted" then evaldate=intnx("&mipInterval.", reporting_dt, horizon, "SAME");;
469 instid = substr(instid,1,find(instid,'_',-length(instid))-1);
475 analysis_run_name = "&analysis_run_name";
476 load_id = "&analysis_run_type";
477 project_name = "&cycle_name";
483 if upcase(rating_agency) eq 'S&P' then
485 select(initial_risk_rating_num);
487 otherwise initial_risk_rating = 'N/A';
491 else if upcase(rating_agency) eq 'FICO' then
492 initial_risk_rating = input(rating_grade, 8.);
495 initial_risk_rating = "N/A";
501 if not missing(scenario_name) then do;
502 scenario_name = strip(substr(scenario_name, find(scenario_name, "-")+1));
506 else if horizon eq 0 then do;
507 %do i=1 %to &scen_cnt;
508 scenario_id = "&&scen_id_&i";
509 scenario_name = "&&scen_nm_&i";
515%mend run_postcode_ccar_provision;
517%run_postcode_ccar_provision