SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_create_ctm_pmx.sas
1/*---------------------------------------------------------------------------------
2 * NAME: irmst_create_ctm_pmx.sas
3 *
4 * PURPOSE: Convert an input TM set to a Cumulative TM set and
5 * finally into a PMX that can be used by MIP/RD environment
6 *
7 * NOTE:
8 *
9 * MACRO OPTIONS:
10 * input_tm_set - Name of the input TM set
11 * output_pmx - Name of the output PMX
12 * debug - OPTIONAL: Specify TRUE to keep intermediate tables
13 *
14 *--------------------------------------------------------------------------------- */
15%macro irmst_create_ctm_pmx(
16 input_tm_set = ,
17 output_pmx = ,
18 debug = FALSE
19 ) / minoperator;
20
21 %local _debug_
22 meta_var;
23
24 /*-----------------------
25 * Align debug parameter
26 *-----------------------*/
27 %if %qupcase(&debug) in (Y YES 1 TRUE) %then
28 %let _debug_ = YES;
29 %else
30 %let _debug_ = NO;
31
32 /*----------------------------
33 * Prepare for IML processing
34 *----------------------------*/
35 %let meta_var = modeling_system_name
36 modeling_system_version
37 model_group_name
38 master_risk_scenario_name
39 mip_scenario_name
40 insttype
41 scenario_date
42 from_risk_rating;
43
44 data work.temp_matrix (drop = &meta_var)
45 work.temp_matrix_meta (keep = &meta_var);
46 set &input_tm_set;
47 run;
48
49 /*---------------------------------------------------
50 * Use IML to convert to cumulative transition matrix
51 *---------------------------------------------------*/
52 proc iml;
53 use work.temp_matrix;
54 read all var _all_
55 into TM[colname = rating];
56 close work.temp_matrix;
57
58 use work.temp_matrix_meta;
59 read all var {model_group_name mip_scenario_name insttype}
60 into model_scen_char;
61 close work.temp_matrix_meta;
62
63 m = nrow(TM);
64 n = ncol(TM);
65 /*-------------------------------------------------------------
66 * Remove negatives in matrices using element maximum operator
67 *-------------------------------------------------------------*/
68 TM = TM<>0;
69 /*-----------------------------------
70 * Convert to cumulative from time 0
71 *-----------------------------------*/
72 previous_model_scen_char = {'NULL' 'NULL' 'NULL'};
73 do i = 0 to m/n-1;
74 current_model_scen_char = model_scen_char[1 + i*n, ];
75 /*-----------------------------------------
76 * Check if start of new model or scenario
77 *-----------------------------------------*/
78 if current_model_scen_char[1] ^= previous_model_scen_char[1] |
79 current_model_scen_char[2] ^= previous_model_scen_char[2] |
80 current_model_scen_char[3] ^= previous_model_scen_char[3] then
81 goto next;
82 TM[1+i*n:(i+1)*n, ] = TM[1+(i-1)*n:i*n, ] * TM[1+i*n:(i+1)*n, ];
83 next:
84 previous_model_scen_char = current_model_scen_char;
85 end;
86
87 CTM = TM;
88 create work.temp_cumulative_trans_matrix1
89 from CTM[colname = rating];
90 append from CTM;
91 close work.temp_cumulative_trans_matrix1;
92 quit;
93
94 data work.temp_cumulative_trans_matrix2;
95 merge work.temp_matrix_meta
96 work.temp_cumulative_trans_matrix1;
97 run;
98
99 /*-------------------------------------------------------
100 * Convert into pmx, hashing name with md5 function.
101 * Variables used as input are all obtainable within UDL
102 *-------------------------------------------------------*/
103 data &output_pmx (drop = &meta_var
104 lookup_key);
105 length _name_ $32
106 lookup_key $128;
107 set work.temp_cumulative_trans_matrix2;
108 lookup_key = catx("_",
109 upcase(insttype),
110 upcase(strip(put(mip_scenario_name, 32.))),
111 put(scenario_date, date9.),
112 upcase(from_risk_rating));
113 %if %qupcase(&_debug_) eq YES %then
114 %do;
115 put 'The following string will be hashed and used as a lookup key "' lookup_key + (-1) '"';
116 %end;
117 _name_ = put(md5(lookup_key), $hex32.);
118 run;
119
120 /*----------------------------------------------
121 * If debug set to NO, drop intermediate tables
122 *----------------------------------------------*/
123 %if %qupcase(&_debug_) eq NO %then
124 %do;
125 proc sql;
126 drop table work.temp_matrix,
127 work.temp_matrix_meta,
128 work.temp_cumulative_trans_matrix1,
129 work.temp_cumulative_trans_matrix2;
130 quit;
131 %end;
132
133%mend irmst_create_ctm_pmx;