<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Create a nullvector to have a nxn-matrix to calculate MWB in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935419#M6221</link>
    <description>&lt;P&gt;Hi I try to calculate a MWB;&amp;nbsp;&lt;SPAN&gt;In&amp;nbsp;&lt;/SPAN&gt;&lt;A title="Mathematics" href="https://en.wikipedia.org/wiki/Mathematics" target="_blank" rel="noopener"&gt;mathematics&lt;/A&gt;&lt;SPAN&gt;, particularly&amp;nbsp;&lt;/SPAN&gt;&lt;A title="Matrix (mathematics)" href="https://en.wikipedia.org/wiki/Matrix_(mathematics)" target="_blank" rel="noopener"&gt;matrix theory&lt;/A&gt;&lt;SPAN&gt;, a&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;band matrix&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;or&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;banded matrix&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;is a&amp;nbsp;&lt;/SPAN&gt;&lt;A title="" href="https://en.wikipedia.org/wiki/Sparse_matrix" target="_blank" rel="noopener"&gt;sparse matrix&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;whose non-zero entries are confined to a diagonal&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;band&lt;/I&gt;&lt;SPAN&gt;, comprising the&amp;nbsp;&lt;/SPAN&gt;&lt;A title="Main diagonal" href="https://en.wikipedia.org/wiki/Main_diagonal" target="_blank" rel="noopener"&gt;main diagonal&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;and zero or more diagonals on either side.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And it requires a nxn-matrix ,but my data looks like this:&amp;nbsp; And I think the best way to calculate it when the matrix don't have the same dimensions is to add a nullvector, in my case when Mk1=scale1&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data pseudo_data;
input SCALE $ mk2 mk3 mk4 mk5 mk6 mk7;
datalines;
scale1 0.620073 0.585710 0.742480 0.654074 0.152773 0.828327
scale2 0.030940 0.081121 0.505554 0.495800 0.024913 0.874568
scale3 0.493812 0.464746 0.675302 0.900584 0.240976 0.112287
scale4 0.194194 0.483504 0.650082 0.795761 0.112740 0.145614
scale5 0.427196 0.986343 0.778883 0.631170 0.623107 0.586194
scale6 0.037071 0.375161 0.217043 0.893637 0.779019 0.161867
scale7 0.186883 0.830461 0.038186 0.000778 0.336085 0.586100
;
run;

/* ex rclassorgcount dataset */
data rclassorgcount;
input SOMETHING_THAT;
datalines;
100
200
150
250
300
350
400
;
run;

%let rcmigrdist=mk2 mk3 mk4 mk5 mk6 mk7; /* # of mk's*/
%let K=7; /*scale*/
%let K_Max=10; /*how many mk's it could possibly be depending on the dataset you running*/
%let SOMETHING_THAT=SOMETHING_THAT; /*something else in my real code; count(SOMETHING) as SOMETHING_THAT*/

proc iml;
    use pseudo_data;
        read all var {&amp;amp;rcmigrdist.} into rc_migr_dist; /* Load matrix with movements shares p_ij */
    close pseudo_data;

    use rclassorgcount;
        read all var {&amp;amp;SOMETHING_THAT.} into rc_orig_count_vec; /* Load vector with number of humans per movement i, Ni */
    close rclassorgcount;

    /* Calc Matrix_normal_u */
    M_norm_u = 0;
    do i = 1 to &amp;amp;K. - 1;
        sum_p = 0;
        maxval = max(abs(i - &amp;amp;K.), abs(i + (&amp;amp;K_Max. - &amp;amp;K.) - 1));
        N_i = rc_orig_count_vec[i];
        do j = i + 1 to &amp;amp;K.;
            sum_p = sum_p + (rc_migr_dist[i, j] / 100); /* Assuming percentages are given, convert to decimal */
        end;
        /*print sum_p;*/
        temp = maxval * N_i * sum_p;
        M_norm_u = M_norm_u + temp;
    end;
    create M_norm_u var {"Matrix_normal_u"}; 
    append from M_norm_u;
    close M_norm_u;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And you see that the log says:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;153 end;&lt;BR /&gt;ERROR: (execution) Invalid subscript or subscript out of range.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I add the nullvector for mk1 in this case?&amp;nbsp; &amp;nbsp;there is more matrix operations&amp;nbsp; then later&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;M_norm_u&lt;/TD&gt;&lt;TD&gt;Upper&lt;BR /&gt;MWB&lt;/TD&gt;&lt;TD&gt;UMWB_skalad&lt;/TD&gt;&lt;TD&gt;M_norm_l&lt;/TD&gt;&lt;TD&gt;Lower&lt;BR /&gt;MWB&lt;/TD&gt;&lt;TD&gt;LMWB_skalad&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(A,B,C is calculated numbers that the matrix could calculated but not the other where there is 0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(i dont post it here) beacuse I think there should be a step before all the actual calculations, like before the &amp;lt;actual&amp;gt; proc iml-step?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jul 2024 08:19:02 GMT</pubDate>
    <dc:creator>cleokatt</dc:creator>
    <dc:date>2024-07-11T08:19:02Z</dc:date>
    <item>
      <title>Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935419#M6221</link>
      <description>&lt;P&gt;Hi I try to calculate a MWB;&amp;nbsp;&lt;SPAN&gt;In&amp;nbsp;&lt;/SPAN&gt;&lt;A title="Mathematics" href="https://en.wikipedia.org/wiki/Mathematics" target="_blank" rel="noopener"&gt;mathematics&lt;/A&gt;&lt;SPAN&gt;, particularly&amp;nbsp;&lt;/SPAN&gt;&lt;A title="Matrix (mathematics)" href="https://en.wikipedia.org/wiki/Matrix_(mathematics)" target="_blank" rel="noopener"&gt;matrix theory&lt;/A&gt;&lt;SPAN&gt;, a&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;band matrix&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;or&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;banded matrix&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;is a&amp;nbsp;&lt;/SPAN&gt;&lt;A title="" href="https://en.wikipedia.org/wiki/Sparse_matrix" target="_blank" rel="noopener"&gt;sparse matrix&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;whose non-zero entries are confined to a diagonal&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;band&lt;/I&gt;&lt;SPAN&gt;, comprising the&amp;nbsp;&lt;/SPAN&gt;&lt;A title="Main diagonal" href="https://en.wikipedia.org/wiki/Main_diagonal" target="_blank" rel="noopener"&gt;main diagonal&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;and zero or more diagonals on either side.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And it requires a nxn-matrix ,but my data looks like this:&amp;nbsp; And I think the best way to calculate it when the matrix don't have the same dimensions is to add a nullvector, in my case when Mk1=scale1&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data pseudo_data;
input SCALE $ mk2 mk3 mk4 mk5 mk6 mk7;
datalines;
scale1 0.620073 0.585710 0.742480 0.654074 0.152773 0.828327
scale2 0.030940 0.081121 0.505554 0.495800 0.024913 0.874568
scale3 0.493812 0.464746 0.675302 0.900584 0.240976 0.112287
scale4 0.194194 0.483504 0.650082 0.795761 0.112740 0.145614
scale5 0.427196 0.986343 0.778883 0.631170 0.623107 0.586194
scale6 0.037071 0.375161 0.217043 0.893637 0.779019 0.161867
scale7 0.186883 0.830461 0.038186 0.000778 0.336085 0.586100
;
run;

/* ex rclassorgcount dataset */
data rclassorgcount;
input SOMETHING_THAT;
datalines;
100
200
150
250
300
350
400
;
run;

%let rcmigrdist=mk2 mk3 mk4 mk5 mk6 mk7; /* # of mk's*/
%let K=7; /*scale*/
%let K_Max=10; /*how many mk's it could possibly be depending on the dataset you running*/
%let SOMETHING_THAT=SOMETHING_THAT; /*something else in my real code; count(SOMETHING) as SOMETHING_THAT*/

proc iml;
    use pseudo_data;
        read all var {&amp;amp;rcmigrdist.} into rc_migr_dist; /* Load matrix with movements shares p_ij */
    close pseudo_data;

    use rclassorgcount;
        read all var {&amp;amp;SOMETHING_THAT.} into rc_orig_count_vec; /* Load vector with number of humans per movement i, Ni */
    close rclassorgcount;

    /* Calc Matrix_normal_u */
    M_norm_u = 0;
    do i = 1 to &amp;amp;K. - 1;
        sum_p = 0;
        maxval = max(abs(i - &amp;amp;K.), abs(i + (&amp;amp;K_Max. - &amp;amp;K.) - 1));
        N_i = rc_orig_count_vec[i];
        do j = i + 1 to &amp;amp;K.;
            sum_p = sum_p + (rc_migr_dist[i, j] / 100); /* Assuming percentages are given, convert to decimal */
        end;
        /*print sum_p;*/
        temp = maxval * N_i * sum_p;
        M_norm_u = M_norm_u + temp;
    end;
    create M_norm_u var {"Matrix_normal_u"}; 
    append from M_norm_u;
    close M_norm_u;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And you see that the log says:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;153 end;&lt;BR /&gt;ERROR: (execution) Invalid subscript or subscript out of range.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I add the nullvector for mk1 in this case?&amp;nbsp; &amp;nbsp;there is more matrix operations&amp;nbsp; then later&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;M_norm_u&lt;/TD&gt;&lt;TD&gt;Upper&lt;BR /&gt;MWB&lt;/TD&gt;&lt;TD&gt;UMWB_skalad&lt;/TD&gt;&lt;TD&gt;M_norm_l&lt;/TD&gt;&lt;TD&gt;Lower&lt;BR /&gt;MWB&lt;/TD&gt;&lt;TD&gt;LMWB_skalad&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(A,B,C is calculated numbers that the matrix could calculated but not the other where there is 0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(i dont post it here) beacuse I think there should be a step before all the actual calculations, like before the &amp;lt;actual&amp;gt; proc iml-step?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 08:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935419#M6221</guid>
      <dc:creator>cleokatt</dc:creator>
      <dc:date>2024-07-11T08:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935421#M6222</link>
      <description>Since you are asking a question about IML, better post it at IML forum:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/bd-p/sas_iml" target="_blank"&gt;https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/bd-p/sas_iml&lt;/A&gt;&lt;BR /&gt;And calling &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;</description>
      <pubDate>Thu, 11 Jul 2024 08:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935421#M6222</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-07-11T08:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935424#M6223</link>
      <description>&lt;P&gt;I have just moved this topic to "SAS/IML and Matrix Computations" - board (where it belongs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 08:43:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935424#M6223</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-07-11T08:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935426#M6224</link>
      <description>&lt;P&gt;Oh, thank you very much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 08:51:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935426#M6224</guid>
      <dc:creator>cleokatt</dc:creator>
      <dc:date>2024-07-11T08:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935432#M6225</link>
      <description>&lt;P&gt;1. What is a MWB? Reference?&lt;/P&gt;
&lt;P&gt;2. In your program, the&amp;nbsp;rc_migr_dist matrix is a 7x6 matrix. The error is because you are trying to access the 7th column of a matrix that has only 6 columns. The error is in the loop that iterates over j:&lt;BR /&gt;&lt;STRONG&gt;do j = i + 1 to &amp;amp;K.;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;3. Your matrix is not banded, so I don't understand why your started your post talking about banded matrices.&lt;/P&gt;
&lt;P&gt;4. Your matrix does not look like it contains percentages, so I don't understand the comment /*&amp;nbsp;Assuming percentages are given, convert to decimal */. However, if you want to divide the matrix by 100, do it OUTSIDE the loops after you read the matrix:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    use pseudo_data;
        read all var {&amp;amp;rcmigrdist.} into rc_migr_dist; /* Load matrix with movements shares p_ij */
    close pseudo_data;
    rc_migr_dist = rc_migr_dist / 100; /* Assuming percentages are given, convert to decimal */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;5. You can make the error go away by changing the upper limit of the inner loop to &amp;amp;K-1 or ncol(rc_migr_dist)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* No need to loop:
        sum_p = 0;
        do j = i + 1 to &amp;amp;K.-1;
            sum_p = sum_p + rc_migr_dist[i,j];
        end;
*/
sum_p = sum( rc_migr_dist[i, i+1:&amp;amp;K-1] );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;6. I think you would be wise to read the dimensions of the data inside IML by using nrow(rc_migr_dist) and&amp;nbsp;ncol(rc_migr_dist). This is preferable to using a hard-coded macro such as K=7.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 09:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935432#M6225</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-07-11T09:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935437#M6226</link>
      <description>&lt;P&gt;I did a little research, and the OP might be asking about the MWB statistic on p. 24-25 of this paper:&amp;nbsp;&lt;A href="https://www.bankingsupervision.europa.eu/banking/tasks/internal_models/shared/pdf/instructions_validation_reporting_credit_risk.en.pdf" target="_blank"&gt;Instructions for reporting the validation results of internal models - IRB Pillar I models for credit risk (europa.eu)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the paper is analyzing Markov transition matrices whereas the matrix in the OP example is not a transition matrix because the rows do not sum to 1. To learn about transition matrices in IML, see&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/iml/2016/07/07/markov-transition-matrices-sasiml.html" target="_blank"&gt;Markov transition matrices in SAS/IML - The DO Loop&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/iml/2023/07/05/terminal-markov-chain.html" target="_blank"&gt;The probability of reaching a terminal state in a Markov chain - The DO Loop (sas.com)&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 11 Jul 2024 10:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935437#M6226</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-07-11T10:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935438#M6227</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Yes I know. But how can I solve the issue with nx(n-1) matrix? Add a null vector? That was my thought&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 10:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935438#M6227</guid>
      <dc:creator>cleokatt</dc:creator>
      <dc:date>2024-07-11T10:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935439#M6228</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;</description>
      <pubDate>Thu, 11 Jul 2024 10:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935439#M6228</guid>
      <dc:creator>cleokatt</dc:creator>
      <dc:date>2024-07-11T10:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935440#M6229</link>
      <description>&lt;P&gt;If there are 7 states, then each cell indicates the proportion of accounts that transitioned from State=i into State=j during the time period. If no account transitioned to State=7, then the last column of your 7x7 matrix should contain all zeros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If "add a nullvector" means "add a column of 0s," then I agree. Otherwise, explain a "nullvector" in this context. In matrix theory, a null vector is a vector v such that A*v=0 for the matrix A. But I don't think you are using that definition(?).&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 10:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935440#M6229</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-07-11T10:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935441#M6230</link>
      <description>&lt;P&gt;A={0,0,0,0,0}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sorry &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in my case : mk1={0,0,0,0,0,0,0]&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 10:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935441#M6230</guid>
      <dc:creator>cleokatt</dc:creator>
      <dc:date>2024-07-11T10:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935449#M6231</link>
      <description>&lt;P&gt;I suggest you read in the names of the variables dynamically (instead of using a macro) and then add the first column if necessary:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc iml;
    use pseudo_data;
        read all var _NUM_ into rc_migr_dist[colname=varNames]; /* Load matrix with movements shares p_ij */
    close pseudo_data;
    nr = nrow(rc_migr_dist);
    print varNames;
    if upcase(varNames)[1] ^= "MK1" then do;
       rc_migr_dist = j(nr, 1, 0) || rc_migr_dist;
       varNames = "MK1" || varNames;
    end;
    print rc_migr_dist[r=varNames c=varNames];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Be aware that this empirical estimate of the transition matrix will be singular. You are specifying a system that will never allow a transition to the first state. If this is not what you want, then use a small positive probability (such as 1E-3) for the first column and adjust the remaining probabilities so that the rows sum to 1.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 12:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935449#M6231</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-07-11T12:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935450#M6232</link>
      <description>&lt;P&gt;Fix it before you get into IML.&lt;/P&gt;
&lt;P&gt;You have 7 observations and only 6 analysis variables.&amp;nbsp; If you want to make sure there are 7 analysis variables then just make a new variable that is all missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case you seem to be naming the variable MK1 to MK7 but you didn't create the MK1 variable.&lt;/P&gt;
&lt;P&gt;So you can just run this code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data square;
  length scale $8 mk1-mk7 8 ;
  set psuedo_data;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't know which how many MK variables there should be just first count the number of observations and put it into a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select count(*) into :nobs trimmed from psuedo_data;
quit;
data square;
  length scale $8 mk1-mk&amp;amp;nobs 8;
  set psuedo_data;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jul 2024 12:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935450#M6232</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-11T12:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935485#M6233</link>
      <description />
      <pubDate>Thu, 11 Jul 2024 14:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935485#M6233</guid>
      <dc:creator>cleokatt</dc:creator>
      <dc:date>2024-07-11T14:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935486#M6234</link>
      <description>yes, that was the problem that my matrix was nx(n-1)</description>
      <pubDate>Thu, 11 Jul 2024 14:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935486#M6234</guid>
      <dc:creator>cleokatt</dc:creator>
      <dc:date>2024-07-11T14:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935488#M6235</link>
      <description>&lt;P&gt;the query you posted. Just to be sure, hehe. That should be before my code;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc iml;
    use pseudo_data;
        read all var {&amp;amp;rcmigrdist.} into rc_migr_dist; /* Load matrix with movements shares p_ij */
    close pseudo_data;

    use rclassorgcount;
        read all var {&amp;amp;SOMETHING_THAT.} into rc_orig_count_vec; /* Load vector with number of humans per movement i, Ni */
    close rclassorgcount;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or after? instead? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 14:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935488#M6235</guid>
      <dc:creator>cleokatt</dc:creator>
      <dc:date>2024-07-11T14:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935493#M6236</link>
      <description>&lt;P&gt;The changes that we've discussed would make your program look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
    use pseudo_data;
        read all var _NUM_ into rc_migr_dist[colname=varNames]; /* Load matrix with movements shares p_ij */
    close pseudo_data;
    nr = nrow(rc_migr_dist);
    if upcase(varNames)[1] ^= "MK1" then do;
       rc_migr_dist = j(nr, 1, 0) || rc_migr_dist;
       varNames = "MK1" || varNames;
    end;
    if nr^=ncol(rc_migr_dist) then 
      print "ERROR: Matrix is not square";

    rc_migr_dist = rc_migr_dist / 100; /* ??? Is this necessary? */
    print rc_migr_dist[r=varNames c=varNames];

    use rclassorgcount;
        read all var {&amp;amp;SOMETHING_THAT.} into rc_orig_count_vec; /* Load vector with number of humans per movement i, Ni */
    close rclassorgcount;

    /* Calc Matrix_normal_u */
    M_norm_u = 0;
    do i = 1 to &amp;amp;K. - 1;
        maxval = max(abs(i - &amp;amp;K.), abs(i + (&amp;amp;K_Max. - &amp;amp;K.) - 1));
        N_i = rc_orig_count_vec[i];
        sum_p = sum( rc_migr_dist[i, i+1:nr] );
        /*print sum_p;*/
        temp = maxval * N_i * sum_p;
        M_norm_u = M_norm_u + temp;
    end;
    create M_norm_u var {"Matrix_normal_u"}; 
    append from M_norm_u;
    close M_norm_u;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jul 2024 14:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935493#M6236</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-07-11T14:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935495#M6237</link>
      <description>&lt;P&gt;thanks! I will have a look, but is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;[colname=varNames]; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;      read all var _NUM_ into rc_migr_dist[colname=varNames]; /* Load matrix with movements shares p_ij */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;is it necessary? do I have to have it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;The changes that we've discussed would make your program look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc iml;
    use pseudo_data;
        read all var _NUM_ into rc_migr_dist[colname=varNames]; /* Load matrix with movements shares p_ij */
    close pseudo_data;
    nr = nrow(rc_migr_dist);
    if upcase(varNames)[1] ^= "MK1" then do;
       rc_migr_dist = j(nr, 1, 0) || rc_migr_dist;
       varNames = "MK1" || varNames;
    end;
    if nr^=ncol(rc_migr_dist) then 
      print "ERROR: Matrix is not square";

    rc_migr_dist = rc_migr_dist / 100; /* ??? Is this necessary? */
    print rc_migr_dist[r=varNames c=varNames];

    use rclassorgcount;
        read all var {&amp;amp;SOMETHING_THAT.} into rc_orig_count_vec; /* Load vector with number of humans per movement i, Ni */
    close rclassorgcount;

    /* Calc Matrix_normal_u */
    M_norm_u = 0;
    do i = 1 to &amp;amp;K. - 1;
        maxval = max(abs(i - &amp;amp;K.), abs(i + (&amp;amp;K_Max. - &amp;amp;K.) - 1));
        N_i = rc_orig_count_vec[i];
        sum_p = sum( rc_migr_dist[i, i+1:nr] );
        /*print sum_p;*/
        temp = maxval * N_i * sum_p;
        M_norm_u = M_norm_u + temp;
    end;
    create M_norm_u var {"Matrix_normal_u"}; 
    append from M_norm_u;
    close M_norm_u;&lt;/CODE&gt;&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 15:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935495#M6237</guid>
      <dc:creator>cleokatt</dc:creator>
      <dc:date>2024-07-11T15:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935497#M6238</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;do I have to have it?&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I included that information so that you can easily check the names of the variables in the input matrix. But you can ignore that suggestion if you prefer an alternative.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 15:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935497#M6238</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-07-11T15:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create a nullvector to have a nxn-matrix to calculate MWB</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935523#M6239</link>
      <description>&lt;P&gt;Before of course.&amp;nbsp; Fix the data using normal coding before venturing off into the world of matrix operations.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 19:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-a-nullvector-to-have-a-nxn-matrix-to-calculate-MWB/m-p/935523#M6239</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-11T19:50:58Z</dc:date>
    </item>
  </channel>
</rss>

