I have a parametrization table that mentions whether the (i,j) th element of "matrix 1" is zero, residual of the row sum or has to be read from the data table. I also have a data table with all the values for different segments. How do I construct the matrix?
For example, let's say "param_table" is the parametrization table:
data param_table;
infile datalines dsd;
length FieldName $20 FieldSourceTable $20;
input Matrix_Id Column_Order Row_Order IsZero IsRowResidual IsColumnResidual FieldName FieldSourceTable;
datalines;
1, 1, 1, 0, 1, 0, ., .
1, 1, 2, 0, 0, 0, xyz, table1
1, 1, 3, 0, 0, 0, abc, table1
1, 2, 1, 1, 0, 0, ., .
1, 2, 2, 0, 0, 0, pqr, table1
1, 2, 3, 0, 0, 0, mno, table1
1, 3, 1, 0, 0, 0, ab, table1
1, 3, 2, 0, 0, 0, pq, table1
1, 3, 3, 0, 1, 0, ., .
;
"table 1" is the actual data containing the values and references from earlier table:
data table1;
input Year (country method Segment) ( : $12.)
ABC XYZ PQR MNO AB PQ;
datalines;
2017 France ABC Retail 0.2 0.5 0.4 0.3 0.6 0.1
2017 France XYZ Corporate 0.1 0.5 0.4 0.2 0.6 0.2
;
run;
How do I create matrices with these rules for each row (each key set) in table 1? For example, matrix for row 1 of "table1" would be:
(1-ab) 0 ab
xyz pqr pq
abc mno (1-abc-mno)
(1,1)th and (3,3) th elements are row residuals, therefore are (1 - sum of rest of the row), whereas (1,2)th element is 0:
0.4 0 0.6
0.5 0.4 0.1
0.1 0.3 0.6
I have added the data steps for file "param_table" which contains the references (the column names) and if it is zero or row residual. Also added the "table1" file which contains the actual values. For each row of "table1" we should have a matrix based on the rules mentioned in param_table.
Thanks!
Each matrix defined in
param_tablewill correspond to a 2-D array associated with each row intable1. Suppose you have macromatrixfierthat generates the source code statements needed to map from thetable1data into a specified array (i.e. matrix).The macro will have to examine the parameter data to determine if the settings it contains are rational with regards to code generation.
Determine how large the target array needs to be. Also, presume there is only one source table per matrix defined
Code generate DATA Step statements for assigning a value directly.
Code generate DATA Step statements for assigning a zero value.
Code generate DATA Step statements for computing row residuals.
Code generate DATA Step statements for computing column residuals.
Assemble the statements in a DATA Step.
Resolve the parameters as applied to data