SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_script_dma_expansion.sas
1/*----------------------------------------------------------------------------
2 * NAME: irmst_script_dma_expansion.sas
3 * (DMA Expansion Script: Input Portfolio)
4 *
5 * PURPOSE: - Execution configuration code for DMA task
6 * - Creates an Analysis Run to perform the following steps:
7 * - DMA preparation
8 * - Register corresponding expanded portfolio data object in RGF
9 * (Data Definition and Analysis Data)
10 *
11 * NOTES: Assumes the modeling systems below are in the same workgroup:
12 * - Segment-level modeling system
13 * - Loan-level modeling system (optional)
14 *
15 *----------------------------------------------------------------------------*/
16/*-------------------------------------------
17 * DMA Expansion Script: Input Parameters
18 *-------------------------------------------*/
19
20/* TGT Authentication Ticket */
21%let rgf_tgt_ticket = ${globals.ticket};
22
23/* Get the root location of the SAS Risk Workgroup Application */
24%let sas_risk_workgroup_dir = ${globals.sas_risk_workgroup_dir};
25
26/* Cycle Id */
27%let cycle_id = ${context.cycle.key};
28
29/* Analysis Run Id */
30%let analysis_run_id = ${context.analysisRun.key};
31
32/* Model Run Configuration Analysis Data Key */
33%let trans_matrix_data_key = ${params.TRANSITIONMATRIX.key};
34
35/* Log Level: 1-4 */
36%let log_level = ${params.LOGLEVEL};
37
38/* Align log specification */
39%if &log_level gt 1 %then
40%do;
41 %let log_debug = true;
42%end;
43%else
44%do;
45 %let log_debug = false;
46%end;
47
48/* ********************************************* */
49
50/* Initialize the environment */
51%include "&sas_risk_workgroup_dir./groups/Public/SASRiskManagementCore/cycles/&cycle_id./init.sas" / lrecl = 32000 source2;
52
53/* Set logging options (based on the value of LOG_LEVEL macro variable) */
54%irm_set_logging_options();
55
56/*---------------
57 * DMA Expansion
58 *---------------*/
59
60 /*--------------------------------------------------------------------------
61 * Set the following required macro variables by navigating transition matrix links:
62 * seg_model_portfolio_key - Data Preparation Output Portfolio Key
63 * seg_lvl_model_run_key - Segment-level Model Run Key
64 * seg_lvl_model_ms_name - Segment-level MIP Modeling System Name
65 * seg_lvl_model_ms_version - Segment-level MIP Modeling System Version
66 * seg_lvl_model_ms_workgroup - Segment-level MIP Modeling System Workgroup
67 *--------------------------------------------------------------------------*/
68 /* Segment-level Model Info */
69 %let seg_model_portfolio_key =;
70 %let seg_lvl_model_key =;
71 %let seg_lvl_model_run_key =;
72 %let seg_lvl_model_ms_name =;
73 %let seg_lvl_model_ms_version =;
74 %let seg_lvl_model_ms_workgroup =;
75
76 /* Find the analysis run that created the transition matrix */
77 %irm_rest_get_rgf_analysis_run(host = &rgf_protocol.://&rgf_host.
78 , server = &rgf_service.
79 , solution = &rgf_solution.
80 , port = &rgf_port.
81 , tgt_ticket = %superq(rgf_tgt_ticket)
82 , filter = filter=hasObjectLinkTo(%str(%')%upcase(&rgf_solution.)%str(%'),'analysisData_analysisRun_out',&trans_matrix_data_key.,0)
83 , outds = analysis_run
84 , outds_params = analysis_run_params
85 , outVarTicket = ticket
86 , outSuccess = httpSuccess
87 , outResponseStatus = responseStatus
88 );
89
90 /*-------------------------------------------------------------------------
91 * Fetch the segment level model and portfolio info from the analysis run
92 *------------------------------------------------------------------------- */
93 %let segParmStr=;
94 %let portParmStr=;
95 data _null_;
96 set analysis_run_params;
97 if parameterName eq 'SEGLEVELMODEL' then do;
98 call symputX('segParmStr',parameterValue);
99 end;
100 if parameterName eq 'PORTFOLIO' then do;
101 call symputX('portParmStr',parameterValue);
102 end;
103 run;
104 proc lua restart;
105 submit;
106 local JSON = require 'risk.common.json'
107 local segParmTbl = JSON:decode(sas.symget('segParmStr'))
108 local modelRunKey = segParmTbl.modelRunHandle:gsub(".-|(%d+)|.*","%1")
109 local modelKey = segParmTbl.handle:gsub(".-|(%d+)|.*","%1")
110 sas.symput('seg_lvl_model_run_key',modelRunKey)
111 sas.symput('seg_lvl_model_key',modelKey)
112
113 local portParmTbl = JSON:decode(sas.symget('portParmStr'))
114 local portKey = portParmTbl.handle:gsub(".-|(%d+)|.*","%1")
115 sas.symput('seg_model_portfolio_key',portKey)
116 endsubmit;
117 run;
118
119 /*---------------------------------------------------
120 * From the segment level model, get the MIP MS info
121 *--------------------------------------------------- */
122 %irm_rest_get_rgf_model(host = &rgf_protocol.://&rgf_host.
123 , server = &rgf_service.
124 , solution = &rgf_solution.
125 , port = &rgf_port.
126 , tgt_ticket = %superq(rgf_tgt_ticket)
127 , key = &seg_lvl_model_key.
128 , outds = model_info
129 , outds_params = model_params
130 , outVarTicket = ticket
131 , outSuccess = httpSuccess
132 , outResponseStatus = responseStatus
133 );
134 data _null_;
135 set model_info;
136 call symputX('seg_lvl_model_ms_name',mipModelingSystemName);
137 call symputX('seg_lvl_model_ms_workgroup',mipModelingSystemWorkgroup);
138 call symputX('seg_lvl_model_ms_version',mipModelingSystemVersion);
139 run;
140
141 /*----------------------------------------------
142 * Retrieve the specified modeling system SK/ID
143 *----------------------------------------------*/
144 %let httpSuccess = 0;
145 %let responseStatus = ;
146 %let ticket_ms = ;
147 %irm_rest_get_mip_ms_info(host = &mip_protocol.://&mip_host
148 , server = &mip_service
149 , port = &mip_port
150 , tgt_ticket = %superq(rgf_tgt_ticket)
151 , workgroup = &seg_lvl_model_ms_workgroup
152 , outds = work.tmp_mip_msinfo
153 , outVarTicket = ticket_ms
154 , outSuccess = httpSuccess
155 , outResponseStatus = responseStatus
156 , restartLUA = Y
157 , clearCache = Y
158 )
159
160 data _null_;
161 set work.tmp_mip_msinfo;
162
163 if upcase(modelingSystemName) eq upcase("&seg_lvl_model_ms_name") and
164 upcase(modelingSystemVersion) eq upcase("&seg_lvl_model_ms_version") then
165 call symputx("tgt_ms_sk", modelingSystemId, "L");
166 run;
167
168 /*--------------------------------------------
169 * Retrieve information about MIP model group
170 *--------------------------------------------*/
171 %let httpSuccess = 0;
172 %let responseStatus = ;
173 %let ticket_workgroup = ;
174 %irmst_get_model_group_maps(model_group_kind = EVALUATION
175 , ms_sk = &tgt_ms_sk
176 , add_seg_lvl_ms_sk = &tgt_ms_sk
177 , out_model_group_map = work.model_group_map_dma
178 , mipurl = &mip_protocol.://&mip_host.:&mip_port./&mip_service
179 , tgt_ticket = %superq(rgf_tgt_ticket)
180 , debug = &log_debug
181 , host = &mip_protocol.://&mip_host
182 , server = &mip_service
183 , port = &mip_port
184 , workgroup = &seg_lvl_model_ms_workgroup
185 , authMethod = token
186 , outds = work._tmp_workgroups_
187 , outVarTicket = ticket_workgroup
188 , outSuccess = httpSuccess
189 , outResponseStatus = responseStatus
190 , restartLUA = Y
191 , clearCache = Y
192 )
193
194 /*----------------------------------
195 * Retrieve portfolio analysis data
196 *----------------------------------*/
197 %let httpSuccess = 0;
198 %let responseStatus = ;
199 %let ticket_portfoilo_get = ;
200 %irm_rgf_retrieve_analysis_data(key = &seg_model_portfolio_key
201 , libref = &dr_libref
202 , outds = work.mod_credit_portfolio_0
203 , outds_partition_list = work.portfolio_partition_list
204 , out_type = deferred
205 , outds_dataInfo = work.portfolio_dataInfo
206 , outds_dataDef = work.portfolio_dataDef
207 , host = &rgf_protocol.://&rgf_host
208 , server = &rgf_service
209 , solution = &rgf_solution
210 , port = &rgf_port
211 , tgt_ticket = %superq(rgf_tgt_ticket)
212 , outVarTicket = ticket_portfoilo_get
213 , outSuccess = httpSuccess
214 , outResponseStatus = responseStatus
215 , restartLUA = Y
216 , clearCache = Y
217 )
218
219 /* Placeholder: For prep_growth and prep_overrides - Outputs work.mod_credit_portfolio_prep_ov and work.classification_vars */
220
221 /*------------------
222 * Enrich portfolio
223 *------------------*/
224 %let httpSuccess = 0;
225 %let responseStatus = ;
226 %let ticket_workgroup = ;
227 %irmst_create_port_expanded(function_package = work.rating_format
228 , in_control_table =
229 , in_model_group_info = work.model_group_map_dma
230 , in_portfolio = work.mod_credit_portfolio_0 /* work.mod_credit_portfolio_prep_ov */
231 , out_unrequired_subset =
232 , out_portfolio = work.mod_credit_portfolio
233 , where_stmt = 1 eq 1
234 , obs = MAX
235 , mipurl = &mip_protocol.://&mip_host.:&mip_port./&mip_service
236 , tgt_ticket = %superq(rgf_tgt_ticket)
237 , host = &mip_protocol.://&mip_host
238 , server = &mip_service
239 , port = &mip_port
240 , workgroup = &seg_lvl_model_ms_workgroup
241 , authMethod = token
242 , outds = work._tmp_workgroups_
243 , outVarTicket = ticket_workgroup
244 , outSuccess = httpSuccess
245 , outResponseStatus = responseStatus
246 , restartLUA = Y
247 , clearCache = Y
248 )
249
250 /*-------------------------------------------
251 * Upload modified portfolio data set to RGF
252 *-------------------------------------------*/
253 %let httpSuccess = 0;
254 %let responseStatus = ;
255 %let ticket_upload = ;
256
257 /* Get name and version of portfolio schema */
258 data _null_;
259 set portfolio_dataDef;
260 call symputx("schemaName", schemaName, "L");
261 call symputx("schemaVersion", schemaVersion, "L");
262 run;
263
264 %irm_rgf_store_analysis_data(ds_in = work.mod_credit_portfolio
265 /* Analysis Data Parameters */
266 , analysis_data_name = Credit Portfolio modified for DMA
267 , analysis_data_desc = Modified portfolio data for the base date %sysfunc(inputn(&base_dt, yymmdd10.), yymmddd10.).\nCreated in the analysis run: &analysis_run_id..
268 , base_date = &base_dt
269 , cycle_id = &cycle_id
270 , status_cd = Preliminary
271 , visibility_cd = Private /* or Shared */
272 , analysis_run_id = &analysis_run_id.
273 /* Data Definition Parameters */
274 , libref = &dr_libref
275 , schema_name = &schemaName.
276 , schema_version = &schemaVersion.
277 /* Output tables */
278 , out_exceptions = upload_exceptions
279 , out_analysis_data = upload_analysis_data
280 , out_partition_list = upload_partition_list
281 , out_data_definition = upload_data_definition
282 , out_link_instance = upload_link_instance
283 /* Connection Parameters */
284 , host = &rgf_protocol.://&rgf_host
285 , server = &rgf_service
286 , solution = &rgf_solution
287 , port = &rgf_port
288 , tgt_ticket = %superq(rgf_tgt_ticket)
289 , outVarTicket = ticket_upload
290 , outSuccess = httpSuccess
291 , outResponseStatus = responseStatus
292 )