SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_get_scenarios_from_rsm.sas
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 SAS Institute Inc. Cary, NC, USA
3*/
4
5/**
6 \file
7\anchor irmst_get_scenarios_from_rsm
8
9 \brief Create an economics dataset (that matches MIP requirement) from SAS Risk Scenario Manager (RSM) and SAS Risk Governance Framework (RGF) using analysis_run_id
10
11 param [in] analysis_run_id ID of analysis run
12 param [in] bep_x_mrs_tbl BEP x MRS configuration table
13 param [in] base_dt Base date of the analysis run
14 param [in] out_scen_meta Name of scenario metadata (output table)
15 param [in] out_scen_data Name of scenario data (output table)
16 param [in] rgf_protocol Protocol for RGF
17 param [in] rgf_host Host name for RGF
18 param [in] rgf_port Server port for RGF. Default value is 7980
19 param [in] rgf_service Name of the Web Application Server that provides the REST service for RGF. Default value is SASRiskGovernanceFramework
20 param [in] rgf_solution Solution identifer for RGF content packages. Default value is stm
21 param [in] rsm_protocol Protocol for RSM
22 param [in] rsm_host Host name for RSM
23 param [in] rsm_port Server port for RSM. Default value is 7980
24 param [in] rsm_service Name of the Web Application Server that provides the REST service for RSM. Default value is SASRiskScenarioManager
25 param [in] tgt_ticket Specify generated TGT
26 param [in] debug OPTIONAL: TRUE / FALSE
27
28 \author SAS Institute Inc.
29 \date 2020
30*/
31%macro irmst_get_scenarios_from_rsm(
32 analysis_run_id = ,
33 bep_x_mrs_tbl = ,
34 base_dt = ,
35 out_scen_meta = work.scenario_info,
36 out_scen_data = work.scenario_data,
37 rgf_protocol = ,
38 rgf_host = ,
39 rgf_port = 7980,
40 rgf_service = SASRiskGovernanceFramework,
41 rgf_solution = stm,
42 rsm_protocol = ,
43 rsm_host = ,
44 rsm_port = 7980,
45 rsm_service = SASRiskScenarioManager,
46 tgt_ticket = ,
47 debug = false
48 );
49
50 %local ticket
51 httpSuccess
52 responseStatus
53 TotRuns
54 tbls_to_del;
55
56 /*-------------------------------------------------------------------------------------
57 * Retrieve the Master Risk Scenarios (MRS) registered in SAS Risk Governance Framework
58 *-------------------------------------------------------------------------------------*/
59 %let ticket =;
60 %let httpSuccess = 0;
61 %let responseStatus =;
62 %irm_rest_get_rgf_mrs(
63 host = &rgf_protocol.://&rgf_host.,
64 server = &rgf_service.,
65 solution = &rgf_solution.,
66 port = &rgf_port.,
67 tgt_ticket = %superq(tgt_ticket),
68 filter = filter=hasObjectLinkTo('%upcase(&rgf_solution.)','analysisRun_masterRisk',&analysis_run_id.,0),
69 details_flg = Y,
70 outds = work.master_risk_scenarios,
71 outVarTicket = ticket,
72 outSuccess = httpSuccess,
73 outResponseStatus = responseStatus,
74 restartLUA = Y,
75 clearCache = Y
76 );
77
78 /*-------------------------------------
79 * Set value for macro variable arrays
80 *-------------------------------------*/
81 %let TotRuns = 0;
82
83 data _null_;
84 set work.master_risk_scenarios end = last;
85
86 call symputx(cats("mrs_key_" , put(_N_, 8.)), key , "L");
87 call symputx(cats("mrs_name_" , put(_N_, 8.)), name , "L");
88 call symputx(cats("scenario_id_", put(_N_, 8.)), scenarioId, "L");
89 call symputx(cats("period_type_", put(_N_, 8.)), periodType, "L");
90
91 /* Total number of records processed */
92 if last then
93 call symputx("TotRuns", _N_, "L");
94 run;
95
96 /*----------------------------------------------------------
97 * Retrieve information about Business Evolution Plan (BEP)
98 *----------------------------------------------------------*/
99 %let ticket =;
100 %let httpSuccess = 0;
101 %let responseStatus =;
102 %irm_rest_get_rgf_bep(host = &rgf_protocol.://&rgf_host.,
103 server = &rgf_service.,
104 solution = &rgf_solution.,
105 port = &rgf_port.,
106 tgt_ticket = %superq(tgt_ticket),
107 filter = filter=hasObjectLinkTo('%upcase(&rgf_solution.)','analysisRun_busEvolution',&analysis_run_id.,0),
108 outds = work.bep_summary,
109 outds_details = work.bep_details,
110 outVarTicket = ticket,
111 outSuccess = httpSuccess,
112 outResponseStatus = responseStatus,
113 restartLUA = Y,
114 clearCache = Y
115 );
116
117 /*------------------------------------------------------
118 * Finalize the Scenario name for downstream processing
119 *------------------------------------------------------*/
120 proc sql;
121 create table work.master_risk_scenarios_2 as
122 select t3.key as mrsKey,
123 t3.name as mrsName,
124 t3.mrsShortName,
125 t3.forecastTime,
126 t3.scenarioId as rsmScenarioId,
127 t3.scenarioName as rsmScenarioName,
128 t1.bep_key as bepKey,
129 t2.name as bepName,
130 t2.bepShortName
131 from &bep_x_mrs_tbl. as t1
132 inner join
133 work.bep_summary as t2
134 on t1.bep_key eq t2.key
135 inner join
136 work.master_risk_scenarios as t3
137 on t1.mrs_key eq t3.key
138 order by t1.bep_key,
139 t3.key,
140 t3.forecastTime,
141 t3.scenarioName;
142 quit;
143
144 data &out_scen_meta.;
145 length scenarioId $32.
146 scenarioName $1024.;
147
148 set work.master_risk_scenarios_2;
149 by bepKey
150 mrsKey
151 forecastTime
152 rsmScenarioName;
153
154 /* Construct the scenario id (<BEP>_<MRS>_FT<#>). This will be used as SCENARIO_NAME for the model execution */
155 scenarioId = catx("_", bepShortName, mrsShortName, cats("FT", sum(forecastTime, 0)));
156
157 if first.forecastTime and
158 last.forecastTime then
159 /* There is only one RSM scenario for this forecastTime */
160 scenarioName = catx(" - ", bepName, mrsName, rsmScenarioName);
161 else
162 /* There are multiple RSM scenarios for this forecastTime: They will be collapsed into a single scenario for the downstream analysis */
163 scenarioName = catx(" - ", bepName, mrsName, cats("FT", sum(forecastTime, 0)));
164 run;
165
166 /*-----------------------------------------------
167 * Get content of each scenario then append them
168 *-----------------------------------------------*/
169 %let ticket=;
170 %do i=1 %to &TotRuns.;
171 %let httpSuccess = 0;
172 %let responseStatus =;
173 %irm_rest_get_rsm_scenario(
174 host = &rsm_protocol.://&rsm_host.,
175 server = &rsm_service.,
176 port = &rsm_port.,
177 tgt_ticket = %superq(rgf_tgt_ticket),
178 key = &&scenario_id_&i..,
179 outds = work.tmp_scenario_data_&i._0,
180 outVarTicket = ticket,
181 outSuccess = httpSuccess,
182 outResponseStatus = responseStatus,
183 restartLUA = Y,
184 clearCache = Y
185 );
186
187 /* Exit in case of errors */
188 %if(not &httpSuccess. or not %rsk_dsexist(work.tmp_scenario_data_&i._0)) %then
189 %return;
190
191 /* Set the base_dt column in the output */
192 data work.tmp_scenario_data_&i._1;
193 format base_dt yymmddd10.
194 master_risk_scenario_key 8.
195 master_risk_scenario_name $150.
196 scenario_id $32.;
197 set work.tmp_scenario_data_&i._0;
198
199 base_dt = %sysfunc(inputn(&base_dt., yymmdd10.));
200 master_risk_scenario_key = &&mrs_key_&i..;
201 master_risk_scenario_name = "&&mrs_name_&i..";
202 scenario_id = "&&scenario_id_&i..";
203
204 %if(%sysevalf(%superq(period_type_&i.) ne, boolean)) %then
205 %do;
206 if(missing(interval) and
207 missing(horizon) and
208 not missing(date)) then
209 do;
210 interval = "&&period_type_&i..";
211 horizon = intck(interval, base_dt, date);
212 end;
213 %end;
214 run;
215
216 /* Append current scenario data to the output table */
217 proc append data = work.tmp_scenario_data_&i._1
218 base = work.rsm_scenario_data
219 force;
220 run;
221 %end;
222
223 /*----------------------------
224 * Generate economics dataset
225 *----------------------------*/
226 data work.tmp_scenario_data;
227 length scenarioId $32.
228 scenarioName $1024.;
229 set work.rsm_scenario_data(rename = (
230 master_risk_scenario_key = mrsKey
231 master_risk_scenario_name = mrsName
232 scenario_id = rsmScenarioId
233 scenario_name = rsmScenarioName
234 )
235 );
236 if _N_ eq 1 then
237 do;
238 %irm_build_hash_lookup(
239 hash_name = hScenInfo,
240 hash_table = &&out_scen_meta.,
241 key_vars = mrsKey rsmScenarioId,
242 data_vars = scenarioId scenarioName,
243 multidata = yes
244 );
245 end;
246
247 /* Lookup all scenarioNames associated with this RSM scenario */
248 call missing(scenarioId, scenarioName);
249 do while(hScenInfo.do_over() eq 0);
250 /* Historical scenario values are unique across all scenarios */
251 if(date le base_dt) then
252 call missing(scenarioId, scenarioName);
253 output;
254 end;
255 run;
256
257 /* Sort and remove duplicate values for historical scenario data */
258 proc sort data = work.tmp_scenario_data
259 out = work.tmp_scenario_data_srt
260 nodupkey;
261 by scenarioId
262 scenarioName
263 date
264 horizon
265 variable_name;
266 run;
267
268 /* Transpose and modify to match MIP requirements */
269 proc transpose data = work.tmp_scenario_data_srt
270 out = &out_scen_data (
271 drop = scenarioName
272 _name_
273 rename = (scenarioId = scenario_name)
274 );
275 by scenarioId
276 scenarioName
277 date
278 horizon;
279 id variable_name;
280 var change_value;
281 run;
282
283 /*----------------------------------------------------
284 * If debug not set to TRUE, drop intermediate tables
285 *----------------------------------------------------*/
286 %if %qupcase(&debug.) ne TRUE %then
287 %do;
288 proc sql noprint;
289 select memname
290 into :tbls_to_del separated by ','
291 from dictionary.tables
292 where upcase(libname) eq 'WORK' and
293 find(upcase(memname),'TMP_SCENARIO_DATA_') ne 0;
294
295 drop table work.bep_summary,
296 work.bep_details,
297 work.master_risk_scenarios,
298 work.master_risk_scenarios_2,
299 &tbls_to_del.,
300 work.tmp_scenario_data,
301 work.tmp_scenario_data_srt;
302 quit;
303 %end;
304
305%mend irmst_get_scenarios_from_rsm;