SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_script_balance_sheet_projection.sas
1/* ********************************************* */
2/* Balance Sheet Projection: Input Parameters */
3/* ********************************************* */
4
5/* TGT Authentication Ticket */
6%let rgf_tgt_ticket = ${globals.ticket};
7
8/* Get the root location of the SAS Risk Workgroup Application */
9%let sas_risk_workgroup_dir = ${globals.sas_risk_workgroup_dir};
10
11/* Cycle Id */
12%let cycle_id = ${context.cycle.key};
13
14/* Analysis Run Id */
15%let analysis_run_id = ${context.analysisRun.key};
16
17/* IRM Configuration Set Id */
18%let config_set_id = ${params.CONFIGSETID};
19
20/* Analysis Data key */
21%let credit_risk_key = ${params.CREDITRISKDETAIL.key};
22
23/* Scenario Name */
24%let scenario_name_list = ${params.MRSBEPPAIR};
25
26/* Results are returned like [BEP_Name1 - MRS Name1, BEP_Name2 - MRS Name2]. Get rid of square backets */
27%let scenario_list = %sysfunc(prxchange(s/[\[\]]//i, -1, %superq(scenario_name_list)));
28
29/* Balance Sheet Projection key */
30%let bsp_key = ${params.BSP.key};
31
32/* LASR load method (Append/Replace) */
33%let lasr_load_method = ${params.LASRLOADMETHOD};
34
35/* Log Level: 1-4 */
36%let log_level = ${params.LOGLEVEL};
37
38/* Maximum wait time for IRM job completion: <number of seconds> */
39%let max_wait = ${params.MAXWAIT};
40
41/* ******************* */
42/* Analysis Data Input */
43/* ******************* */
44
45/* Analysis Data key */
46%let analysis_data_key = ${params.CREDITRISKDETAIL.key};
47
48/* Schema Name and Version of the Data Definition object associated with this Analysis Data object */
49%let schema_name = ${params.CREDITRISKDETAIL.nav("analysisData_dataDefinition|RMC")[0].schemaName};
50%let schema_version = ${params.CREDITRISKDETAIL.nav("analysisData_dataDefinition|RMC")[0].schemaVersion};
51
52/* Get the analysis run key that created the credit risk detail data */
53%let credit_risk_analysis_run = ${params.CREDITRISKDETAIL.nav("analysisData_analysisRun_out|RMC")[0].key};
54
55/* ********************************************* */
56
57/* Initialize the environment */
58%include "&sas_risk_workgroup_dir./groups/Public/SASRiskManagementCore/cycles/&cycle_id./init.sas" / lrecl = 32000 source2;
59
60/* Set logging options (based on the value of LOG_LEVEL macro variable) */
61%irm_set_logging_options();
62
63/* Process LASR load method */
64%let reload_lasr_flg = %irmc_process_lasr_load_method(&lasr_load_method.);
65
66/* Run option table */
67data work.run_option;
68 length
69 config_name $32.
70 config_value $100.
71 ;
72 config_name = "RMC_FA_ID"; config_value = "&rmc_fa_id."; output;
73 config_name = "CYCLE_ID"; config_value = "&cycle_id."; output;
74 config_name = "ANALYSIS_RUN_ID"; config_value = "&analysis_run_id."; output;
75 config_name = "MAX_WAIT"; config_value = "&max_wait."; output;
76 config_name = "LOG_LEVEL"; config_value = "&log_level."; output;
77 config_name = "RELOAD_LASR_FLG"; config_value = "&reload_lasr_flg."; output;
78 config_name = "TGT_TICKET"; config_value = "&rgf_tgt_ticket."; output;
79run;
80
81/* Run the IRM Jobflow for each MRS Scenario to get results for both scenarios in the Balance Sheet */
82%macro run_irm_flow(scenarios);
83 /* create an IRM instance to generate balance sheet line items for each scenario */
84 %do mrs=1 %to %sysfunc(countw(&scenarios., %str(,)));
85 %let curr_scenario = %scan(&scenarios., &mrs., %str(,));
86
87 /* Set Instance Parameters */
88 %let jobflow_category = Analytics;
89 %let jobflow_type = irmst_balance_sheet_projection;
90 %let instance_date = %sysfunc(date(), yymmddp10.);
91 %let instance_time = %sysfunc(prxchange(s/(\d+):(\d+):(\d+)/$1h$2m$3s/i, -1, %sysfunc(time(), tod8.)));
92 %let instanceName = BEP Aggregation Analysis &instance_date._&instance_time.;
93 %let instanceDesc = BEP Aggregation Analysis for the scenario: %lowcase(&curr_scenario.);
94
95 /* Balance sheet projection configuration parameter table */
96 data work.bsp_data_config;
97 length
98 source_data_name $32.
99 analysis_data_key $32.
100 source_data_version $100.
101 scenario_name $512.
102 ;
103 source_data_name = "&schema_name.";
104 analysis_data_key = "&analysis_data_key." ;
105 source_data_version="&schema_version.";
106 scenario_name = "&curr_scenario.";
107 output;
108 run;
109
110 %let instanceKey =;
111 %let jobflow_status = Unknown;
112 %let ticket=;
113 /* Create job flow instance and wait for completion */
114 %irm_rest_create_jobflow_instance(instance_name = &instanceName.
115 , description = &instanceDesc.
116 , entityId = &entity_id.
117 , entityRoleKey = &entity_role_key.
118 , category = &jobflow_category.
119 , jobflowFile = &jobflow_type.
120 , baseDate = &irm_base_dt.
121 , configSetId = &config_set_id.
122 , federatedAreaID = &irm_fa_id.
123 , sourceFederatedAreaId = &irm_fa_id.
124 , src_param_tables = work.run_option
125 , tgt_param_tables = &solutionLibrefPrefix._CFG.RUN_OPTION
126 , src_upload_tables = work.bsp_data_config
127 , tgt_upload_tables = &solutionLibrefPrefix._CFG.bsp_data_config
128 , autoRun = true
129 , wait_flg = Y
130 , pollInterval = 3
131 , maxWait = &max_wait.
132 , host = &irm_protocol.://&irm_host.
133 , port = &irm_port.
134 , tgt_ticket = &rgf_tgt_ticket.
135 , outvar = instanceKey
136 , outVarStatus = jobflow_status
137 );
138
139 %if (&jobflow_status. eq Successful) %then %do;
140
141 /* Get the analysis run parameters for the credit risk run */
142 %let ticket=;
143 %irm_rest_get_rgf_analysis_run(host = &rgf_protocol.://&rgf_host.
144 , server = &rgf_service.
145 , solution = &rgf_solution.
146 , port = &rgf_port.
147 , tgt_ticket = &rgf_tgt_ticket.
148 , key = &credit_risk_analysis_run.
149 , filter =
150 , outds = analysis_run
151 , outds_params = analysis_run_params
152 , fout_code =
153 , outVarTicket = ticket
154 , outSuccess = ar_success
155 , outResponseStatus = ar_status
156 );
157
158 /* Create file with BEP parameter json */
159 filename mrs_info temp;
160
161 /* Get the parameter value for the BEP parameter (will be a JSON Array of BEPs and dependant MRSs) */
162 data _null_;
163 file mrs_info;
164 set analysis_run_params;
165 if parameterName = "BEP" then put parameterValue;
166 run;
167
168 /* Read json file */
169 libname mrs_info json;
170
171 /* Get a mapping of BEP keys to MRS keys */
172 proc sql;
173 create table bep_mrs_info as
174 select scan(r.handle, 2, "|") as bep_key
175 , scan(d.handle, 2, "|") as mrs_key
176 from mrs_info.root r
177 left join mrs_info.dependencies d
178 on r.ordinal_root = d.ordinal_root;
179 quit;
180
181 /* Close file */
182 filename mrs_info clear;
183
184 /* Get unique list of MRS keys and BEP keys */
185 proc sql;
186 select distinct mrs_key
187 into : mrs_keys separated by ','
188 from bep_mrs_info;
189
190 select distinct bep_key
191 into : bep_keys separated by ','
192 from bep_mrs_info;
193 quit;
194
195 /* Get current MRSs that are in our MRS keys */
196 %irm_rest_get_rgf_mrs(host = &rgf_protocol.://&rgf_host.
197 , server = &rgf_service.
198 , solution = &rgf_solution.
199 , port = &rgf_port.
200 , tgt_ticket = &rgf_tgt_ticket.
201 , filter = filter=in(key,&mrs_keys.)%nrstr(&fields=key,name)
202 , details_flg = N
203 , outds = mrs_list
204 , outVarTicket = ticket
205 , outSuccess = mrs_success
206 , outResponseStatus = mrs_status
207 );
208
209 /* Get current BEPs that are in our BEP keys */
210 %irm_rest_get_rgf_bep(host = &rgf_protocol.://&rgf_host.
211 , server = &rgf_service.
212 , solution = &rgf_solution.
213 , port = &rgf_port.
214 , tgt_ticket = &rgf_tgt_ticket.
215 , filter = filter=in(key,&bep_keys.)%nrstr(&fields=key,name,customFields)
216 , outds = bep_list
217 , outVarTicket = ticket
218 , outSuccess = mrs_success
219 , outResponseStatus = mrs_status
220 );
221
222 /* Enhance the bep_mrs_info table to include names */
223 proc sql;
224 create table bep_mrs_info_names as
225 select bm.*
226 , b.name as bep_name
227 , m.name as mrs_name
228 , catx(' - ', b.name, m.name) as scenario_name
229 from bep_mrs_info bm
230 left join bep_list b
231 on input(bm.bep_key, 8.) = b.key
232 left join mrs_list m
233 on input(bm.mrs_key, 8.) = m.key;
234 quit;
235
236 /* Get the most recent Financial Statements results linked to this analysis run */
237 %let fin_statement_key=;
238 %irm_rest_get_rgf_link_instances(host = &rgf_protocol.://&rgf_host.
239 , port = &rgf_port.
240 , tgt_ticket = &rgf_tgt_ticket
241 , linkType = analysisData_analysisRun_out
242 , filter = sortBy=key
243 , outds = link_instance
244 , outVarTicket = ticket
245 , outSuccess = link_success
246 , outResponseStatus = link_status
247 );
248
249 /* Get the key of the Financial Statement results */
250 %if (&link_success. eq 1) %then %do;
251 data link_inst_sort;
252 set link_instance;
253 where businessObject2=&analysis_run_id.;
254 if _N_ = &mrs. then do;
255 call symputx("fin_statement_key", businessObject1, "L");
256 stop;
257 end;
258 run;
259 %end;
260
261 /* Get the key of the current Master Risk Scenario */
262 %let curr_mrs_key=;
263 data _null_;
264 set bep_mrs_info_names;
265 where scenario_name = "&curr_scenario.";
266 if _N_ = 1 then do;
267 call symputx("curr_mrs_key", mrs_key, "L");
268 stop;
269 end;
270 run;
271
272 /* Create a link instance between the MRS used for the current run and the Financial Statements results */
273 %if ("&curr_mrs_key." ne "" and "&fin_statement_key." ne "") %then %do;
274 %irm_rest_create_rgf_link_inst(host = &rgf_protocol.://&rgf_host.
275 , port = &rgf_port.
276 , tgt_ticket = &rgf_tgt_ticket
277 , link_type = masterRisk_analysisData
278 , business_object1 = &curr_mrs_key.
279 , business_object2 = &fin_statement_key.
280 , outds = link_instance
281 , outVarTicket = ticket
282 , outSuccess = new_link_success
283 , outResponseStatus = new_link_status
284 );
285 %end;
286
287 %end;
288
289 %if (&jobflow_status. eq Successful) and &mrs. = %sysfunc(countw(&scenarios., %str(,))) %then %do;
290
291 /* Loop through the scenarios to create links to each AR_MRS combination */
292 %do mrs_cnt=1 %to %sysfunc(countw(&scenarios., %str(,)));
293 %let scenario&mrs_cnt. = %scan(&scenarios., &mrs_cnt., %str(,));
294 /* Get the MRS key based on the selected scenario BEP pair */
295 data _null_;
296 set mrs_list;
297 if find(upcase(strip("&&scenario&mrs_cnt.")), upcase(strip(name))) then call symputx("mrs_key_&mrs_cnt.", key, "L");
298 run;
299
300 /* Create a link between the analysis_run and Master Risk Scenario */
301 %irm_rest_create_rgf_link_inst(host = &rgf_protocol.://&rgf_host.
302 , port = &rgf_port.
303 , tgt_ticket = &rgf_tgt_ticket
304 , link_instance_id = analysisRun_masterRisk_&analysis_run_id._&&mrs_key_&mrs_cnt.
305 , link_type = analysisRun_masterRisk
306 , business_object1 = &analysis_run_id.
307 , business_object2 = &&mrs_key_&mrs_cnt.
308 , outds = link_instance
309 , outVarTicket = link_ticket_out
310 , outSuccess = link_success
311 , outResponseStatus = link_status
312 );
313 %end;
314
315 %end;
316 %end;
317%mend;
318
319/* Scenario_list is a parameter in the model */
320%run_irm_flow(%superq(scenario_list));