<?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: Applying Scalar, and Inverse Scalar in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/356241#M3467</link>
    <description>&lt;P&gt;The problem is that (H ^= 0) first evaluates to a matrix of zeros and ones, so when this is applied to D with elementwise multiplication it either preserves the existing values in D, or sets them to zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is possible to get the Inverse Scalar Matrix using a small trick. First subtract&amp;nbsp;one from G, next calculate H as you have above, finally add back the one.&amp;nbsp; The overall effect is to place a one, rather than a zero, at every location in H corresponding to one of the modified values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;F = (D#(C^=1))[,+];
G = (1-F)/(E-F);

H = (G-1)#(C=1) + 1;
J = D # H;
print H [l='Inverse Scalar Matrix'], J [l='Finished Matrix'];&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 May 2017 06:34:48 GMT</pubDate>
    <dc:creator>IanWakeling</dc:creator>
    <dc:date>2017-05-05T06:34:48Z</dc:date>
    <item>
      <title>Applying Scalar, and Inverse Scalar</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/355842#M3463</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question regarding the capabilites of proc iml. Suppose I have a matrix of probabilites, then want to multiply each cell directly by a scalar matrix, so that only some of the probabilites go up while some remain the same. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8702i1D9D29F8B3FFD52D/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="example scalar.JPG" title="example scalar.JPG" /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I'd like to multiply the other values in each row by a scalar in order for each row to still sum to one. But the scalar also needs to be computed for each row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This can be accomplished with excel's solver, as shown:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8703iF5358C17D5BB023D/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="example scalar 2.JPG" title="example scalar 2.JPG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would this be possible to accomplish in IML, or would I need to look to a different procedure, or is there a better way to go about this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is code to set up the beginning matrices in SAS:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
	A = {	0.20	0.15	0.30	0.35,
			0.15	0.25	0.35	0.25,
			0.10	0.20	0.50	0.20,
			0.25	0.25	0.30	0.20};
	B = A[ ,+];
	C = {	1.0	1.2	1.0	1.0,
			1	1	1.2	1.0,
			1	1	1	1.2,
			1.2	1	1	1};
		
	D = A#C;
	E = D[ ,+];

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Justin&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 03:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/355842#M3463</guid>
      <dc:creator>jl1005</dc:creator>
      <dc:date>2017-05-04T03:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Applying Scalar, and Inverse Scalar</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/355866#M3464</link>
      <description>&lt;P&gt;I think you are over complicating things by suggesting you need to&amp;nbsp;use the Excel solver.&amp;nbsp; Once you know the sum of values in each row that have been increased (F), then it is a simple calculation to find the row scalars (G).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;F = (D#(C^=1))[,+];
G = (1-F)/(E-F);
print G;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 May 2017 07:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/355866#M3464</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2017-05-04T07:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: Applying Scalar, and Inverse Scalar</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/355954#M3465</link>
      <description>&lt;P&gt;It looks like you want SOLVE() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc iml;
	A = {	0.20	0.15	0.30	0.35,
			0.15	0.25	0.35	0.25,
			0.10	0.20	0.50	0.20,
			0.25	0.25	0.30	0.20};

	C = {	1.0	1.2	1.0	1.0,
			1	1	1.2	1.0,
			1	1	1	1.2,
			1.2	1	1	1};
	
     D=A#C;
Y=j(nrow(A),1,1);
X=solve(D,Y);
want=D#X`;
print want (want[,+]);	
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WANT&lt;/P&gt;
&lt;P&gt;0.2467064 0.0667512 0.3381478 0.3483947 &amp;nbsp; 1&lt;BR /&gt; 0.1850298 0.0927101 0.4734069 0.2488533 &amp;nbsp; 1&lt;BR /&gt; 0.1233532 0.074168 0.5635796 0.2388992 &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt; 0.3700595 0.0927101 0.3381478 0.1990827 &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 13:08:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/355954#M3465</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-04T13:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Applying Scalar, and Inverse Scalar</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/356070#M3466</link>
      <description>&lt;P&gt;That works great; thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now to apply that to the new matrix, so that the values of G multiply all the other cells in D, &amp;nbsp;I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	H = G#(C=1);  /*To create similar scalar matrix */
	J = D#(H ^= 0);

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But J isn't showing the values I'd like.&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 18:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/356070#M3466</guid>
      <dc:creator>jl1005</dc:creator>
      <dc:date>2017-05-04T18:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: Applying Scalar, and Inverse Scalar</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/356241#M3467</link>
      <description>&lt;P&gt;The problem is that (H ^= 0) first evaluates to a matrix of zeros and ones, so when this is applied to D with elementwise multiplication it either preserves the existing values in D, or sets them to zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is possible to get the Inverse Scalar Matrix using a small trick. First subtract&amp;nbsp;one from G, next calculate H as you have above, finally add back the one.&amp;nbsp; The overall effect is to place a one, rather than a zero, at every location in H corresponding to one of the modified values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;F = (D#(C^=1))[,+];
G = (1-F)/(E-F);

H = (G-1)#(C=1) + 1;
J = D # H;
print H [l='Inverse Scalar Matrix'], J [l='Finished Matrix'];&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2017 06:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Applying-Scalar-and-Inverse-Scalar/m-p/356241#M3467</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2017-05-05T06:34:48Z</dc:date>
    </item>
  </channel>
</rss>

