SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_enrich_mip_results.sas
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 SAS Institute Inc. Cary, NC, USA
3*/
4
5/**
6 \file
7 \anchor irmst_enrich_mip_results.sas
8
9 \brief irmst_enrich_mip_results enriches the model results with the portfolio table.
10
11 \param [in] in_mip_result_ds Specifies the MIP model results table.
12 \param [in] in_mip_portfolio_ds Specifies the DMA expanded portfolio.
13 \param [in] reverse_rename_stmt Specifies the counterparty rename statement.
14 \param [in] join_vars Variable to be removed from the MIP results table. (Default: instid)
15 \param [out] outds Specifies the output table for the enriched MIP results.
16
17 \author SAS Institute Inc.
18 \date 2021
19*/
20
21%macro irmst_enrich_mip_results(
22 outds = ,
23 in_mip_result_ds = ,
24 in_mip_portfolio_ds = ,
25 reverse_rename_stmt = ,
26 join_vars = instid
27 );
28
29 %local
30 i
31 result_var_list
32 result_var_list_csv
33 ;
34
35 /* Get the list of variables from the model result table (remove INSTID) */
36 %let result_var_list = %rsk_getvarlist(&in_mip_result_ds);
37 %do i = 1 %to %irm_wordcount(&join_vars);
38 %let result_var_list = %sysfunc(prxchange(s/\b%scan(&join_vars,&i)\b//i, -1, &result_var_list));
39 %end;
40 %let result_var_list_csv = %sysfunc(prxchange(s/\s+/%str(, )/i, -1, &result_var_list.));
41
42 /* Join model results with the portfolio table */
43 data &outds;
44 set &in_mip_portfolio_ds.
45 %if(%sysevalf(%superq(reverse_rename_stmt) ne, boolean)) %then %do;
46 (rename = (&reverse_rename_stmt.))
47 %end;
48 ;
49
50 /* Set internal variables for tracking movement changes */
51 length MOVEMENT_ID 8. MOVEMENT_DESC $100.;
52 retain
53 MOVEMENT_ID 1
54 MOVEMENT_DESC "01. Model Output"
55 ;
56
57 rename
58 activationScenario = activation_scenario
59 activationHorizon = activation_horizon
60 ;
61
62 if _N_ = 0 then
63 set &in_mip_result_ds.;
64
65 if _N_ = 1 then do;
66 declare hash hResult(dataset: "&in_mip_result_ds.", multidata: "yes");
67 hResult.defineKey("instid");
68 hResult.defineData(all: "yes");
69 hResult.defineDone();
70 end;
71
72 drop __rc__;
73 call missing(&result_var_list_csv.);
74 __rc__ = hResult.find();
75 /* Check if we found a match */
76 if (__rc__ = 0) then do;
77 /* Loop through all matching records */
78 do while(__rc__ = 0);
79
80 %if &dma_expansion_flg eq Y %then %do;
81 synthetic_instrument_flg = 'N';
82 %end;
83
84 /* Write only original portfolio position or synthetic positions where the activationScenario matches the scenario_id */
85 if(synthetic_instrument_flg = "N" or activationScenario = scenario_id) then
86 output;
87
88 /* Lookup next result */
89 call missing(&result_var_list_csv.);
90 __rc__ = hResult.find_next();
91 end;
92 end;
93 else
94 /* No match was found, write the record anyway (it could happen if there are issues with the MIP model. These positions will have missing scenario name so they can spotted in the reports) */
95 output;
96 run;
97
98%mend irmst_enrich_mip_results;