6%let rgf_tgt_ticket = ${globals.ticket};
9%let sas_risk_workgroup_dir = ${globals.sas_risk_workgroup_dir};
12%let cycle_id = ${context.cycle.key};
15%let run_id = ${context.runId};
18%let run_type = ${context.runType};
21%let analysis_data_key = ${params.ANALYSISDATA.key};
22%let analysis_data_name = ${params.ANALYSISDATA.name};
23%let analysis_data_desc = ${params.ANALYSISDATA.description};
26%let out_analysis_data_name = ${params.OUTANALYSISDATANAME};
27%let out_analysis_data_desc = ${params.OUTANALYSISDATADESC};
30%let schema_name = ${params.ANALYSISDATA.nav(
"analysisData_dataDefinition|RMC")[0].schemaName};
31%let schema_version = ${params.ANALYSISDATA.nav(
"analysisData_dataDefinition|RMC")[0].schemaVersion};
32%let business_category = ${params.ANALYSISDATA.nav(
"analysisData_dataDefinition|RMC")[0].businessCategoryCd};
33%let analysisData_libref = ${params.ANALYSISDATA.nav(
"analysisData_dataDefinition|RMC")[0].libref};
36%let ruleSet_key = ${params.RULESET.key};
37%let ruleSet_type = ${params.RULESET.ruleSetType};
40%let log_level = ${params.LOGLEVEL};
43%let create_rules_audit = No;
51%include
"&sas_risk_workgroup_dir./groups/Public/SASRiskManagementCore/cycles/&cycle_id./init.sas" / lrecl = 32000 source2;
54%irm_set_logging_options();
56%macro extract_lookup_analysis_info(lookupRulesData);
58 set &lookupRulesData.;
59 if (upcase(analysisData) eq
"PLACEHOLDER") then
do;
60 call symput(
'lookup_analysis_json',
'');
62 else if not missing(analysisData) then
do;
63 call symput(
'lookup_analysis_json', analysisData);
66 call symput(
'lookup_analysis_json',
'');
71 %
if &lookup_analysis_json. ne %then %
do;
75 call symput(
'lookupRulesData_obs', nobs);
77 set &lookupRulesData. nobs=nobs;
81 %
do j = 1 %to &lookupRulesData_obs.;
85 set &lookupRulesData.(obs=&j. firstobs=&j.);
86 if (upcase(analysisData) eq
"PLACEHOLDER") then
do;
87 call symput(
'lookup_analysis_json',
'');
89 else if not missing(analysisData) then
do;
90 call symput(
'lookup_analysis_json', analysisData);
93 call symput(
'lookup_analysis_json',
'');
97 filename dqrsjson temp;
101 JSON = %unquote(%str(%
'&lookup_analysis_json%'));
105 libname jsonlibn JSON fileref=dqrsjson;
106 proc transpose data=jsonlibn.alldata(drop=p v) out=lookup_keys;
114 if not missing(key) then call symput(
'lookup_analysis_key', key);
115 else call symput(
'lookup_analysis_key',
'');
119 %let httpSuccess = 0;
120 %let responseStatus =;
121 %irm_rgf_retrieve_analysis_data(key = &lookup_analysis_key.
122 , libref = &dr_libref.
123 , outds = %str(&)schema_name.
124 , outds_partition_list = partition_list
126 , outds_dataInfo = analysis_data
127 , outds_dataDef = data_definition
128 , host = &rgf_protocol.:
129 , server = &rgf_service.
130 , solution = &rgf_solution.
132 , tgt_ticket = &rgf_tgt_ticket.
133 , outVarTicket = ticket
134 , outSuccess = httpSuccess
135 , outResponseStatus = responseStatus
140 %
if(not &httpSuccess. or not %rsk_dsexist(analysis_data)) %then
146 call symputx(
"schema_name", schemaName,
"L");
149 data &lookupRulesData.;
150 length schema_name $32.;
151 set &lookupRulesData.;
152 if (_N_ eq &j. ) then schema_name =
"&schema_name.";
157 data &lookupRulesData.;
158 length schema_name $32.;
159 ruleset_row_key =
'';
166%irm_get_details(libref = &analysisData_libref.
167 , table_name = &schema_name.
168 , table_id = &analysis_data_key.
169 , schema_version = &schema_version.
170 , out_ds = &schema_name.
171 , out_ds_meta = out_ds_meta
172 , out_partition_list = partition_list
177%irm_rest_get_rgf_rule_set(host = &rgf_protocol.:
178 , server = &rgf_service.
179 , solution = &rgf_solution.
181 , tgt_ticket = &rgf_tgt_ticket.
182 , key = &ruleSet_key.
184 , outVarTicket = ticket
185 , outSuccess = httpSuccess
186 , outResponseStatus = responseStatus
191%
if(&ruleSet_type. eq AllocationRuleSet or &ruleSet_type. eq QFactorRuleSet or &ruleSet_type. eq MgtActionRuleSet) %then %
do;
196 filter_exp = prxchange(
's/LOWER\(\s*(\w+)\s*\) like LOWER\(\s*"%([^%]+)%"\s*\)/prxmatch("\/\Q$2\E\/i", $1)/i', -1, filter_exp);
198 filter_exp = prxchange(
"s/(!=)/ne/i", -1, filter_exp);
200 if ruleSetType =
"MgtActionRuleSet" then
do;
201 filter_exp = catt(filter_exp,
" and (FORECAST_TIME ne 0)");
207 %irm_apply_allocation_rules(ds_in = &schema_name.
208 , rule_def_ds = rules_info
209 , exclude_filter_vars = ruleSetKey
210 , custom_filter_var = filter_exp
211 , ds_out = modified_details
212 , ds_out_rule_summary = rule_summary
216 data &solutionId._alloc_rule_summary / view = &solutionId._alloc_rule_summary;
218 ruleSetKey length = 8. label =
"Ruleset Key"
219 rule_condition length = $10000. label =
"Rule Condition"
220 adjustment_value length = $150. label =
"Adjustment Value"
221 measure_var_nm length = $150. label =
"Measure Variable Name"
222 adjustment_type length = $150. label =
"Adjustment Type"
223 allocation_method length = $150. label =
"Allocation Method"
224 aggregation_method length = $32. label =
"Aggregation Method"
225 weight_var_nm length = $150. label =
"Weight Variable Name"
226 weighted_aggregation_flg length = $3. label =
"Weighted Aggregation Flag"
227 affected_row_cnt length = 8. label =
"Affected Row Count"
228 total_row_cnt length = 8. label =
"Total Row Count"
240 weighted_aggregation_flg
246 %let rule_summary_schema_name = %lowcase(&solutionId._alloc_rule_summary);
247 %let filterable_vars = measure_var_nm adjustment_type allocation_method aggregation_method weight_var_nm weighted_aggregation_flg;
248 %let dataDefinition_name = Allocation Rules Summary Schema;
249 %let dataDefinition_desc = Allocation Rules Summary schema definition;
252%
if(&ruleSet_type. eq BusinessRuleSet) %then %
do;
254 ${function:ProcessSpreadsheetParameter(params.RULESETANALYSISLOOKUPDATAMAPPING,
"lookupRulesData")}
257 %extract_lookup_analysis_info(lookupRulesData);
261 create table rules_info_aug as
262 select a.*, b.schema_name from
263 rules_info a left join lookupRulesData b
264 on (a.key eq b.ruleset_row_key) or b.ruleset_row_key eq
''
271 source_table =
"&schema_name.";
272 source_table_desc =
"&analysis_data_name. (&analysis_data_key.)";
273 target_table =
"modified_details";
276 if not missing(schema_name) then lookup_table = schema_name;
279 lookup_key = compress(lookup_key,
'"[]');
280 lookup_key = tranwrd(lookup_key,
',',
'');
281 lookup_data = compress(lookup_data,
'"[]');
282 lookup_data = tranwrd(lookup_data,
',',
'');
286 %irm_run_rules(ds_rule_def = rules_info
287 , ds_out_summary = rule_summary
291 data &solutionId._business_rule_summary / view = &solutionId._business_rule_summary;
293 ruleSetKey length = 8. label =
"Ruleset Key"
296 ruleSetKey = &ruleSet_key.;
299 %let rule_summary_schema_name = %lowcase(&solutionId._business_rule_summary);
300 %let filterable_vars = source_table rule_id rule_name rule_reporting_lev1 rule_reporting_lev2 rule_reporting_lev3 rule_message_txt source_table rule_id;
301 %let dataDefinition_name = Business Rules Summary Schema;
302 %let dataDefinition_desc = Business Rules Summary schema definition;
305%
if(&ruleSet_type. eq ClassificationRuleSet) %then %
do;
309 set rules_info (rename = (classification_value = adjustment_value
310 classification_field = measure_var_nm));
311 filter_exp = prxchange(
's/LOWER\(\s*(\w+)\s*\) like LOWER\(\s*"%([^%]+)%"\s*\)/prxmatch("\/\Q$2\E\/i", $1)/i', -1, filter_exp);
313 filter_exp = prxchange(
"s/(!=)/ne/i", -1, filter_exp);
315 if ruleSetType =
"ClassificationRuleSet" then
do;
316 allocation_method =
"INDIVIDUAL";
317 adjustment_type =
"ABSOLUTE";
322 %irm_apply_allocation_rules(ds_in = &schema_name.
323 , rule_def_ds = rules_info
324 , exclude_filter_vars = ruleSetKey
325 , custom_filter_var = filter_exp
326 , ds_out = modified_details
327 , ds_out_audit = rule_details
328 , ds_out_rule_summary = rule_summary
332 data &solutionId._alloc_rule_summary / view = &solutionId._alloc_rule_summary;
334 ruleSetKey length = 8. label =
"Ruleset Key"
335 rule_condition length = $10000. label =
"Rule Condition"
336 adjustment_value length = $150. label =
"Adjustment Value"
337 measure_var_nm length = $150. label =
"Measure Variable Name"
338 adjustment_type length = $150. label =
"Adjustment Type"
339 allocation_method length = $150. label =
"Allocation Method"
340 aggregation_method length = $32. label =
"Aggregation Method"
341 weight_var_nm length = $150. label =
"Weight Variable Name"
342 weighted_aggregation_flg length = $3. label =
"Weighted Aggregation Flag"
343 affected_row_cnt length = 8. label =
"Affected Row Count"
344 total_row_cnt length = 8. label =
"Total Row Count"
356 weighted_aggregation_flg
362 %let rule_summary_schema_name = %lowcase(&solutionId._alloc_rule_summary);
363 %let filterable_vars = measure_var_nm adjustment_type allocation_method aggregation_method weight_var_nm weighted_aggregation_flg;
364 %let dataDefinition_name = Allocation Rules Summary Schema;
365 %let dataDefinition_desc = Allocation Rules Summary schema definition;
369%
if(&ruleSet_type. eq ClassificationRuleSet and &create_rules_audit eq Yes) %then %
do;
373 call symputx(
"primary_key", primary_key,
"L");
376 data &solutionId._alloc_rule_detail;
378 table_id length = 8. label =
"Table Id"
379 project_id length = 8 label =
"Analysis Cycle Id"
380 load_id length = $32. label =
"Load Id"
381 entity_id length = $32. label =
"Entity Id"
382 workgroup length = $32. label =
"Risk Workgroup"
383 reporting_dt length = 8. label =
"Base Date" format = yymmddd10.
385 set &schema_name. (keep = &primary_key.);
387 measure_name length = $32. label =
"Classification Field"
388 current_txt_value length = $150. label =
"Current Value"
389 previous_txt_value length = $150. label =
"Previous Value"
390 processed_dttm length = 8. label =
"Processed Datetime" format = datetime21.
395 proc append base = &solutionId._alloc_rule_detail
396 data = rule_details force;
399 %let rule_audit_dtl_schema_name = %lowcase(&solutionId._alloc_rule_audit);
400 %let filterable_vars_dtl = classification_field;
401 %let dataDef_name_audit_dtl = Rules Audit Definition;
402 %let dataDef_desc_audit_dtl = Rules Audit schema definition;
406%
if &syscc. <= 4 %then %
do;
408 %irm_rgf_store_analysis_data(ds_in = modified_details
410 , analysis_data_name = &out_analysis_data_name.
411 , analysis_data_desc = &out_analysis_data_desc.
412 , base_date = &base_dt.
413 , cycle_id = &cycle_id.
414 , entity_id = &entity_id.
415 , status_cd = Preliminary
416 , %sysfunc(ifc(&run_type = Analysis Run, analysis_run_id = &run_id., model_run_id = &run_id.))
419 , libref = &analysisData_libref.
420 , schema_name = &schema_name.
421 , schema_version = &schema_version.
424 , out_exceptions = data_exceptions
425 , out_analysis_data = new_analysys_data
426 , out_partition_list = new_partitions
427 , out_data_definition = data_definition
428 , out_link_instance = link_instance
431 , host = &rgf_protocol.:
432 , server = &rgf_service.
433 , solution = &rgf_solution.
435 , tgt_ticket = &rgf_tgt_ticket.
436 , outVarTicket = ticket
437 , outSuccess = httpSuccess
438 , outResponseStatus = responseStatus
443 %irm_rgf_store_analysis_data(ds_in = &rule_summary_schema_name.
445 , analysis_data_name = Adjustments Summary (&analysis_data_name.) - %sysfunc(date(), yymmdd10.) %sysfunc(time(), tod8.)
446 , analysis_data_desc = Summary information about the adjustments that were applied on Analysis Data
object &analysis_data_name. (Object Id: &analysis_data_key.).
447 , base_date = &base_dt.
448 , cycle_id = &cycle_id.
449 , entity_id = &entity_id.
450 , status_cd = Preliminary
451 , %sysfunc(ifc(&run_type = Analysis Run, analysis_run_id = &run_id., model_run_id = &run_id.))
454 , data_definition_name = &dataDefinition_name.
455 , data_definition_desc = &dataDefinition_desc.
456 , libref = &analysisData_libref.
458 , meta_library_name = &dr_library_name.
459 , schema_name = &rule_summary_schema_name.
460 , schema_version = &content_version.
462 , business_category = &business_category.
463 , data_category = AUDIT_SUMMARY
465 , data_type = &ruleSet_type.
467 , filterable_vars = &filterable_vars.
468 , classification_vars =
469 , attributable_vars =
470 , mandatory_segmentation_vars =
473 , constraint_enabled_flg = N
476 , out_exceptions = audit_data_exceptions
477 , out_analysis_data = audit_analysys_data
478 , out_partition_list = audit_partitions
479 , out_data_definition = audit_data_definition
480 , out_link_instance = audit_link_instance
483 , host = &rgf_protocol.:
484 , server = &rgf_service.
485 , solution = &rgf_solution.
487 , tgt_ticket = &rgf_tgt_ticket.
488 , outVarTicket = ticket
489 , outSuccess = httpSuccess
490 , outResponseStatus = responseStatus
495%
if (&syscc. <= 4 and (&ruleSet_type. eq ClassificationRuleSet and &create_rules_audit eq Yes) )%then %
do;
497 %irm_rgf_store_analysis_data(ds_in = &solutionId._alloc_rule_detail
499 , analysis_data_name = Classification Audit (&analysis_data_name.) - %sysfunc(date(), yymmdd10.) %sysfunc(time(), tod8.)
500 , analysis_data_desc = Audit information about the classifications that were applied on Analysis Data
object &analysis_data_name. (Object Id: &analysis_data_key.).
501 , base_date = &base_dt.
502 , cycle_id = &cycle_id.
503 , entity_id = &entity_id.
504 , status_cd = Preliminary
505 , %sysfunc(ifc(&run_type = Analysis Run, analysis_run_id = &run_id., model_run_id = &run_id.))
508 , data_definition_name = &dataDef_name_audit_dtl.
509 , data_definition_desc = &dataDef_desc_audit_dtl.
510 , libref = &analysisData_libref.
512 , meta_library_name = &dr_library_name.
513 , schema_name = &rule_audit_dtl_schema_name.
514 , schema_version = &content_version.
516 , business_category = &business_category.
517 , data_category = AUDIT_SUMMARY
519 , data_type = &ruleSet_type.
521 , filterable_vars = &filterable_vars.
522 , classification_vars =
523 , attributable_vars =
524 , mandatory_segmentation_vars =
527 , constraint_enabled_flg = N
530 , out_exceptions = audit_dtl_data_exceptions
531 , out_analysis_data = audit_dtl_analysys_data
532 , out_partition_list = audit_dtl_partitions
533 , out_data_definition = audit_dtl_data_definition
534 , out_link_instance = audit_dtl_link_instance
537 , host = &rgf_protocol.:
538 , server = &rgf_service.
539 , solution = &rgf_solution.
541 , tgt_ticket = &rgf_tgt_ticket.
542 , outVarTicket = ticket
543 , outSuccess = httpSuccess
544 , outResponseStatus = responseStatus