70%macro irmc_riskagg_corr_mat_parser( ds_in_corr_matrix =
71 , working_libname =work
78 create table &working_libname..bygroup_map as
79 select distinct REPORTING_DT,SCENARIO_ID,RISK_MEASURE,_TYPE_
80 from &ds_in_corr_matrix.;
84 data &working_libname..bygroup_map;
85 set &working_libname..bygroup_map end=last;
88 call symputx(
"bygroup_cnt",index);
94 data &working_libname..raw_matrix_enhanched;
95 set &ds_in_corr_matrix.;
97 declare hash h(dataset:
"&working_libname..bygroup_map");
98 h.defineKey(
"REPORTING_DT",
"SCENARIO_ID");
99 h.defineData(
"index");
130 %
do i_bygroup=1 %to &bygroup_cnt.;
133 create table &working_libname..parm1_data as
134 select distinct _PARM1_ as _PARM_
135 from &working_libname..raw_matrix_enhanched(where=(index=&i_bygroup.))
137 create table &working_libname..parm2_data as
138 select distinct _PARM2_ as _PARM_
139 from &working_libname..raw_matrix_enhanched(where=(index=&i_bygroup.))
144 data &working_libname..parm_data;
145 merge &working_libname..parm1_data &working_libname..parm2_data;
151 select _PARM_, count(_PARM_) into :parm_list separated by " ", :parm_cnt
152 from &working_libname..parm_data;
157 %do i_parm=1 %to &parm_cnt.;
158 %if %sysfunc(NVALID(%scan(&parm_list.,&i_parm.,%str( ))))=0 %then %do;
159 %put ERROR: when defining a correlation matrix, the values of _PARM1_ and _PARM2_ must be valid character
string to be used as a SAS variable name.;
160 %put The attempted invalid
string is: %scan(&parm_list.,&i_parm.,%str( ));
173 data %if &i_bygroup.=1 %then %do;
176 %else %if &i_bygroup.>1 %then %do;
177 &working_libname..matrix_&i_bygroup.;
179 length _PARM1_ $64. _PARM2_ $64. _NAME_ $64.;
182 declare hash h(dataset: "&working_libname..raw_matrix_enhanched(where=(index=&i_bygroup.))");
183 h.defineKey("_PARM1_","_PARM2_");
184 h.defineData("_MEASUREMENT_");
186 call missing(_MEASUREMENT_);
189 %do i_row=1 %to &parm_cnt.;
190 _NAME_="%scan(&parm_list.,&i_row.,%str( ))";
191 %do i_col=1 %to &parm_cnt.;
192 %if &i_row.=&i_col. %then %do;
193 %scan(&parm_list.,&i_col.,%str( ))=1;
196 _PARM1_="%scan(&parm_list.,&i_row.,%str( ))";
197 _PARM2_="%scan(&parm_list.,&i_col.,%str( ))";
198 %scan(&parm_list.,&i_col.,%str( ))=.;
201 %scan(&parm_list.,&i_col.,%str( ))=_MEASUREMENT_;
204 _PARM1_="%scan(&parm_list.,&i_col.,%str( ))";
205 _PARM2_="%scan(&parm_list.,&i_row.,%str( ))";
208 %scan(&parm_list.,&i_col.,%str( ))=_MEASUREMENT_;
211 put 'ERROR: Not enough elements were specified to the define a correct correlation matrix.';
212 call symput("httpSuccess", 0);
221 %if(not &httpSuccess.) %then %do;
227 use %if &i_bygroup.=1 %then %do;
230 %else %if &i_bygroup.>1 %then %do;
231 &working_libname..matrix_&i_bygroup.;
233 read all var {&parm_list.} into corr_mat;
235 eigvalues = eigval(corr_mat);
237 min_eigenvalue=min(eigvalues);
239 if min_eigenvalue<0 then
do;
240 call symputx (
"positive_semi_def_flg",
"FALSE",
"L");
243 call symputx (
"positive_semi_def_flg",
"TRUE",
"L");
247 %
if &positive_semi_def_flg.=FALSE %then %
do;
248 %put ERROR: The correlation matrix &ds_in_corr_matrix. is not positive semi-definite.;
255 %
if &i_bygroup.>1 %then %
do;
256 proc append base=&ds_out_matrix. data=&working_libname..matrix_&i_bygroup.;
264 data &ds_out_matrix.;
265 set &ds_out_matrix. &working_libname..bygroup_map(obs=0 keep=REPORTING_DT SCENARIO_ID RISK_MEASURE _TYPE_);
267 declare hash h(dataset:
"&working_libname..bygroup_map");
268 h.defineKey(
"index");
269 h.defineData(
"REPORTING_DT",
"SCENARIO_ID",
"RISK_MEASURE",
"_TYPE_");
273 drop rc _PARM1_ _PARM2_ _MEASUREMENT_ index;