SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_node_mrs_finalize.sas
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 SAS Institute Inc. Cary, NC, USA
3*/
4
5/** \file
6 \brief Finalize scenario data for downstream processing
7
8 \param[in] ST_PRM.RUN_OPTION Parameter table containing runtime configuration values
9 \param[in] ds_in_cardinality (ST_STG.SCENARIO_CARDINALITY) Input table specifying the total number of IRM partitions
10 \param[in] ds_in_mrs_scenarios (ST_STG.MASTER_RISK_SCENARIOS) Input table containing the list of scenarios to retrieve
11 \param[in] ds_in_rsm_scenario_data (ST_STG.RSM_SCENARIO_DATA) Input table containing scenario data details
12 \param[out] ds_out_scenario_info (ST_STG.SCENARIO_INFO) Output table containing the finalized list of scenarios to be consumed by the downstream processing
13 \param[out] ds_out_scenario_data (ST_STG.SCENARIO_DATA) Output table containing the scenario data to be consumed by the downstream processing
14
15 \details
16
17 In addition the following macro utilities are called:
18
19 | Macro name | Description | Further information |
20 |---------------------------|--------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
21 | irm_session_prepare | Reads RUN_OPTION table and sets logging options | \link irm_session_prepare.sas \endlink |
22 | irm_session_cleanup | Removes all non-IRM WORK datasets/views and deletes all user-created macro variables from workspace session | \link irm_session_cleanup.sas \endlink |
23
24 \ingroup nodes
25 \author SAS Institute Inc.
26 \date 2018
27*/
28
29/* Initialize session */
30%irm_session_prepare();
31
32/* Join Business Evolution Plans, Master Risk Scenario and RSM Scenarios */
33proc sql;
34 create table bep_x_mrs_x_rsm as
35 select
36 t1.bep_key as bepKey
37 , t1.mrs_key as mrsKey
38 , t2.name as bepName
39 , t2.bepShortName
40 , t3.analysis_run_id
41 , t3.name as mrsName
42 , t3.mrsShortName
43 , t3.forecastTime
44 , t3.scenarioId as rsmScenarioId
45 , t3.scenarioName as rsmScenarioName
46 , t3.defaultWeight
47 from
48 &ds_in_bep_x_mrs_config. as t1
49 join
50 &ds_in_bep_summary. as t2 on
51 t1.bep_key = t2.key
52 join
53 &ds_in_mrs_scenarios as t3 on
54 t1.mrs_key = t3.key
55 order by
56 t1.bep_key
57 , t1.mrs_key
58 , t3.forecastTime
59 , t3.scenarioName
60 ;
61quit;
62
63/* Finalize the Scenario name for downstream processing */
64data &ds_out_scenario_info.;
65 length
66 scenarioId $32.
67 scenarioName $1024.
68 ;
69 set bep_x_mrs_x_rsm;
70 by
71 analysis_run_id
72 bepKey
73 mrsKey
74 forecastTime
75 rsmScenarioName
76 ;
77
78 forecastTime = sum(forecastTime, 0);
79 /* Construct the scenario id (<BEP>_<MRS>_FT<#>). This will be used as SCENARIO_NAME for the model execution */
80 scenarioId = catx("_", bepShortName, mrsShortName, cats("FT", forecastTime));
81
82 if first.forecastTime and last.forecastTime then
83 /* There is only one RSM scenario for this forecastTime. */
84 scenarioName = catx(" - ", bepName, mrsName, rsmScenarioName);
85 else
86 /* There are multiple RSM scenarios for this forecastTime: they will be collapsed into a single scenario for the downstream analysis */
87 scenarioName = catx(" - ", bepName, mrsName, cats("FT", forecastTime));
88run;
89
90data tmp_scenario_data;
91 length
92 scenarioId $32.
93 scenarioName $1024.
94 ;
95 set &ds_in_rsm_scenario_data(rename = (master_risk_scenario_key = mrsKey
96 master_risk_scenario_name = mrsName
97 scenario_id = rsmScenarioId
98 scenario_name = rsmScenarioName
99 )
100 );
101 if _N_ = 1 then do;
102 declare hash hScenInfo(dataset: "&ds_out_scenario_info.", multidata: "yes");
103 hScenInfo.defineKey("analysis_run_id", "mrsKey", "rsmScenarioId");
104 hScenInfo.defineData("scenarioId", "scenarioName");
105 hScenInfo.defineDone();
106 end;
107
108 /* Lookup all scenarioNames associated with this RSM scenario */
109 call missing(scenarioId, scenarioName);
110 do while(hScenInfo.do_over() eq 0);
111 /* Historical scenario values are unique across all scenarios */
112 if(date <= base_dt) then
113 call missing(scenarioId, scenarioName);
114 output;
115 end;
116run;
117
118/* Sort and remove duplicate values for historical scenario data */
119proc sort data = tmp_scenario_data
120 out = tmp_scenario_data_srt nodupkey;
121 by
122 analysis_run_id
123 scenarioId
124 scenarioName
125 date
126 horizon
127 variable_name
128 ;
129run;
130
131/* Transpose */
132proc transpose data = tmp_scenario_data_srt
133 out = &ds_out_scenario_data. (drop = _name_);
134 by
135 analysis_run_id
136 scenarioId
137 scenarioName
138 date
139 horizon
140 ;
141 id variable_name;
142 var change_value;
143run;
144
145
146/* Make sure the scenarios are unique (duplicates would appear if multiple RSM scenarios are collapsed by the same forecast time value) */
147proc sort data = &ds_out_scenario_info. (drop = rsmScenarioId rsmScenarioName) nodupkey;
148 by
149 analysis_run_id
150 scenarioId
151 ;
152run;
153
154proc sort data = &ds_out_scenario_data. nodupkey;
155 by
156 analysis_run_id
157 scenarioId
158 date
159 horizon
160 ;
161run;
162
163
164/* Cleanup session */
165%irm_session_cleanup;