<?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 Re: How do I perform matrix multiplication inside of proc model? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-perform-matrix-multiplication-inside-of-proc-model/m-p/523518#M142233</link>
    <description>&lt;P&gt;Thank you. I tried revising with Arrays to try the matrix muliplication and found that I am still hitting a wall. See the code below for the change.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc model data=R_&amp;amp;y._&amp;amp;q._set2   OUTPARMS=M_rho_Initial_&amp;amp;y._&amp;amp;q. ;
	parms M ;
	exogenous M;
	label M='M_factor_t' ;
	array current [7] End_1-End_7;
	array long [7] Endl_1-Endl_7;
	array Scaled [7] scale_1-scale_7;
	Bounds -1 &amp;lt;= M &amp;lt;=1;
	
			
		eq.Esq = COUNT*(
					(   (  ( probnorm((long[1] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[1] )**2  )*Scaled[1]   )+
					(   (  ( probnorm((long[2] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[2] )**2  )*Scaled[2]   )+
					(   (  ( probnorm((long[3] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[3] )**2  )*Scaled[3]   )+
					(   (  ( probnorm((long[4] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[4] )**2  )*Scaled[4]   )+
					(   (  ( probnorm((long[5] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[5] )**2  )*Scaled[5]   )+
					(   (  ( probnorm((long[6] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[6] )**2  )*Scaled[6]   )+
					(   (  ( probnorm((long[7] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[7] )**2  )*Scaled[7]   )
			);
	
	solve M ;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am multiplying through the Matrices and getting the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: The Newton method Jacobian matrix of partial derivatives of the
       equations with respect to the variables to be solved is singular
       at observation 1, for iteration 2. The system of equations cannot
       be solved.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have set this up such that the sum of squared errors is fit on the multiplied matrices, but the matrix should multiply to a single&amp;nbsp;summed value instead of a column; I do not think this is where the issue is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could use further guidance on the Proc Model use and steps, as well as input on the approach, if any help can be provided.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Dec 2018 03:50:38 GMT</pubDate>
    <dc:creator>jserby</dc:creator>
    <dc:date>2018-12-26T03:50:38Z</dc:date>
    <item>
      <title>How do I perform matrix multiplication inside of proc model?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-perform-matrix-multiplication-inside-of-proc-model/m-p/523275#M142164</link>
      <description>&lt;P&gt;Hello! I have found the message board helpful in the past and wanted to reach out now.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to do an M-factor approach (or Z-factor some places) that uses a merton model framework for markov transitions in the rating space.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The approach requires fitting a parameter M in the following equation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(probnorm((Std_norm_av_cum_P - sqrt(&amp;amp;rho.)*M)/(1-&amp;amp;rho.)) - Std_norm_cum_P&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where rho is a chosen correlation&amp;nbsp;established as a fixed value outside the model; Std_norm_av_cum_P is the long term transition probabilities, and&amp;nbsp;Std_norm_cum_P is the current time period transitions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was able to run proc model using OLS to determine M using the following model.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc model data=R_&amp;amp;y._&amp;amp;q._set   OUTPARMS=M_rho_Initial_&amp;amp;y._&amp;amp;q. ;
	parms M ;
	label M='M_factor_t' ;
		Std_norm_cum_P = probnorm((Std_norm_av_cum_P - sqrt(&amp;amp;rho.)*M)/(1-&amp;amp;rho.)) ;
	
	fit Std_norm_cum_P ;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The matrix analyzed here is a 7X7 matrix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the model needs&amp;nbsp;to&amp;nbsp;actually minimize using the system demonstrated in the chart which is attached. The system multiples by the outer matrices which are the Count by starting rating level and the long term PD by end rating level. These values are available in other datasets (both are 7X1 matrices).&lt;/P&gt;&lt;P&gt;I just do not know how to multiply them within the Proc Model statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried bringing in all three datasets view the data step, then I tried manually creating the arrays (although, admittedly, I am not good at using arrays and&amp;nbsp;that may be the solution, but I do not know how to do it). The following code is where I ended up and it is not working:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc model data=R_&amp;amp;y._&amp;amp;q._set   OUTPARMS=M_rho_Initial_&amp;amp;y._&amp;amp;q. ;
	parms M ;
	exogenous M;
	label M='M_factor_t' ;
	Array count_ARRAY {7} c1-c7 ( &amp;amp;Count_list. );
	Array PD_1_yr_ARRAY {7} p1-p7 ( &amp;amp;PD_1_yr_list. );

		eq.Esq = (count_ARRAY{1-7} * ((probnorm((Std_norm_av_cum_P - sqrt(&amp;amp;rho.)*M)/(1-&amp;amp;rho.)) - Std_norm_cum_P)*PD_1_yr_ARRAY{1-7})**2;
	/* WEIGHT */
	solve M ;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Where&amp;nbsp;&amp;amp;Count_list.&amp;nbsp; are the counts by rating level and&amp;nbsp;&amp;amp;PD_1_yr_list. are the long term PDs by rating level. As you can see I am trying to matrix multiply using the arrays and it is not working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help out with how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using SAS 9.4 and do not have Proc Optmodel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Dec 2018 15:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-perform-matrix-multiplication-inside-of-proc-model/m-p/523275#M142164</guid>
      <dc:creator>jserby</dc:creator>
      <dc:date>2018-12-22T15:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I perform matrix multiplication inside of proc model?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-perform-matrix-multiplication-inside-of-proc-model/m-p/523291#M142171</link>
      <description>I don't know enough about what you're doing to offer a solution, but you are definitely referencing your arrays incorrectly.  &lt;BR /&gt;&lt;BR /&gt;You can read up this short tutorial if you'd like: &lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I suspect you need to loop and then add or sum those values throughout but like I said, I don't understand what you need here. &lt;BR /&gt;&lt;BR /&gt;Good Luck.</description>
      <pubDate>Sat, 22 Dec 2018 18:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-perform-matrix-multiplication-inside-of-proc-model/m-p/523291#M142171</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-22T18:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I perform matrix multiplication inside of proc model?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-perform-matrix-multiplication-inside-of-proc-model/m-p/523518#M142233</link>
      <description>&lt;P&gt;Thank you. I tried revising with Arrays to try the matrix muliplication and found that I am still hitting a wall. See the code below for the change.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc model data=R_&amp;amp;y._&amp;amp;q._set2   OUTPARMS=M_rho_Initial_&amp;amp;y._&amp;amp;q. ;
	parms M ;
	exogenous M;
	label M='M_factor_t' ;
	array current [7] End_1-End_7;
	array long [7] Endl_1-Endl_7;
	array Scaled [7] scale_1-scale_7;
	Bounds -1 &amp;lt;= M &amp;lt;=1;
	
			
		eq.Esq = COUNT*(
					(   (  ( probnorm((long[1] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[1] )**2  )*Scaled[1]   )+
					(   (  ( probnorm((long[2] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[2] )**2  )*Scaled[2]   )+
					(   (  ( probnorm((long[3] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[3] )**2  )*Scaled[3]   )+
					(   (  ( probnorm((long[4] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[4] )**2  )*Scaled[4]   )+
					(   (  ( probnorm((long[5] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[5] )**2  )*Scaled[5]   )+
					(   (  ( probnorm((long[6] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[6] )**2  )*Scaled[6]   )+
					(   (  ( probnorm((long[7] - sqrt(&amp;amp;rho.)*M)/sqrt(1-&amp;amp;rho.)) - current[7] )**2  )*Scaled[7]   )
			);
	
	solve M ;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am multiplying through the Matrices and getting the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: The Newton method Jacobian matrix of partial derivatives of the
       equations with respect to the variables to be solved is singular
       at observation 1, for iteration 2. The system of equations cannot
       be solved.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have set this up such that the sum of squared errors is fit on the multiplied matrices, but the matrix should multiply to a single&amp;nbsp;summed value instead of a column; I do not think this is where the issue is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could use further guidance on the Proc Model use and steps, as well as input on the approach, if any help can be provided.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2018 03:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-perform-matrix-multiplication-inside-of-proc-model/m-p/523518#M142233</guid>
      <dc:creator>jserby</dc:creator>
      <dc:date>2018-12-26T03:50:38Z</dc:date>
    </item>
  </channel>
</rss>

