SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_create_pd_pmx.sas
1/*---------------------------------------------------------------------------------
2 * NAME: irmst_create_pd_pmx.sas
3 *
4 * PURPOSE: Store the default probability vector from an input TM set and
5 * converted into a PMX that can be used in a MIP/RD environment
6 *
7 * NOTES: Assumes the last column of input TM stores the default probabilities
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_pd_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 n = ncol(TM);
59 /*-------------------------------------------------------------
60 * Remove negatives in matrices using element maximum operator
61 *-------------------------------------------------------------*/
62 TM = TM<>0;
63
64 /*----------------------------------------------------
65 * Store only the last column into the default vector
66 *----------------------------------------------------*/
67 PD = TM[ ,n];
68 create work.temp_pd_vector1
69 from PD[colname = 'PD'];
70 append from PD;
71 close work.temp_pd_vector1;
72 quit;
73
74 data work.temp_pd_vector2;
75 merge work.temp_matrix_meta
76 work.temp_pd_vector1;
77 run;
78
79 /*-------------------------------------------------------
80 * Convert into pmx, hashing name with md5 function.
81 * Variables used as input are all obtainable within UDL
82 *-------------------------------------------------------*/
83 data &output_pmx (drop = &meta_var
84 lookup_key);
85 length _name_ $32
86 lookup_key $128;
87 set work.temp_pd_vector2;
88 lookup_key = catx("_",
89 upcase(insttype),
90 upcase(strip(put(mip_scenario_name, 32.))),
91 put(scenario_date, date9.),
92 upcase(from_risk_rating));
93 %if %qupcase(&_debug_) eq YES %then
94 %do;
95 put 'The following string will be hashed and used as a lookup key "' lookup_key + (-1) '"';
96 %end;
97 _name_ = put(md5(lookup_key), $hex32.);
98 run;
99
100 /*----------------------------------------------
101 * If debug set to NO, drop intermediate tables
102 *----------------------------------------------*/
103 %if %qupcase(&_debug_) eq NO %then
104 %do;
105 proc sql;
106 drop table work.temp_matrix,
107 work.temp_matrix_meta,
108 work.temp_pd_vector1,
109 work.temp_pd_vector2;
110 quit;
111 %end;
112
113%mend irmst_create_pd_pmx;