<?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: IML code in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-code/m-p/74116#M455</link>
    <description>One immediate change you can make for efficiency and accuracy is to use the SOLVE function instead of taking the inverse:&lt;BR /&gt;
&lt;BR /&gt;
instead of &lt;BR /&gt;
&lt;BR /&gt;
H2=wnor*inv(i-lamda*wnor)*x*beta;&lt;BR /&gt;
&lt;BR /&gt;
use&lt;BR /&gt;
&lt;BR /&gt;
H2=wnor*solve( i-lamda*wnor,x)*beta;</description>
    <pubDate>Fri, 02 Oct 2009 15:43:25 GMT</pubDate>
    <dc:creator>Hutch_sas</dc:creator>
    <dc:date>2009-10-02T15:43:25Z</dc:date>
    <item>
      <title>IML code</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-code/m-p/74115#M454</link>
      <description>I want to reduce this code so that it can run fast and use less memory.&lt;BR /&gt;
&lt;BR /&gt;
Please if your too good with IML can you please help me.&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
Jacksmith&lt;BR /&gt;
&lt;BR /&gt;
proc iml;&lt;BR /&gt;
	use hedonic2;&lt;BR /&gt;
		read all var {lsale_amt} into y;&lt;BR /&gt;
		read all var {tract_zip} into tract;&lt;BR /&gt;
		read all var {ltv	bath	bed	age	gla1000	lot1000	gla2	lot2	bed2	bath2	age2	tax&lt;BR /&gt;
		MONTH1 MONTH2 MONTH3 MONTH4 MONTH5 MONTH6 MONTH7 MONTH8 MONTH9 MONTH10 MONTH11 MONTH12} into x;&lt;BR /&gt;
	use tract_mean; read all var {count} into ncount;&lt;BR /&gt;
	use wnor; read all var _all_ into wnor;&lt;BR /&gt;
	use outest_step1; 	&lt;BR /&gt;
		read all var {a1	a2	a3	a4	a5	a6	a7	a8	a9	a10	a11	a12	a13	a14	a15	a16	a17	a18	a19	a20	&lt;BR /&gt;
		a21	a22	a23	a24	a25	} into beta;&lt;BR /&gt;
&lt;BR /&gt;
	nn=nrow(y);&lt;BR /&gt;
	beta1=beta`;&lt;BR /&gt;
	beta=beta1[1:24];&lt;BR /&gt;
	lamda=beta1[25];&lt;BR /&gt;
&lt;BR /&gt;
	i=i(nn);&lt;BR /&gt;
	H2=wnor*inv(i-lamda*wnor)*x*beta;&lt;BR /&gt;
	H=H2||tract;&lt;BR /&gt;
&lt;BR /&gt;
	create H from H; append from H; close H;&lt;BR /&gt;
quit;&lt;BR /&gt;
options nomprint nonotes NOPRINTMSGLIST NOSOURCE NOSOURCE2;&lt;BR /&gt;
&lt;BR /&gt;
data hedonic2;&lt;BR /&gt;
	merge hedonic2 H(rename=(col1=H col2=tract_zip));&lt;BR /&gt;
	by tract_zip;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
		proc model data=hedonic2 noprint &lt;BR /&gt;
		;&lt;BR /&gt;
		endogenous wy;&lt;BR /&gt;
		lsale_amt=&lt;BR /&gt;
		a1*	ltv	+&lt;BR /&gt;
		a2*	bath	+&lt;BR /&gt;
		a3*	bed	+&lt;BR /&gt;
		a4*	age	+&lt;BR /&gt;
		a5*	gla1000	+&lt;BR /&gt;
		a6*	lot1000	+&lt;BR /&gt;
		a7*	gla2	+&lt;BR /&gt;
		a8*	lot2	+&lt;BR /&gt;
		a9*	bed2	+&lt;BR /&gt;
		a10*	bath2	+&lt;BR /&gt;
		a11*	age2	+&lt;BR /&gt;
		a12*	tax	+&lt;BR /&gt;
&lt;BR /&gt;
		a13*	month1	+&lt;BR /&gt;
		a14*	month2	+&lt;BR /&gt;
		a15*	month3	+&lt;BR /&gt;
		a16*	month4	+&lt;BR /&gt;
		a17*	month5	+&lt;BR /&gt;
		a18*	month6	+&lt;BR /&gt;
		a19*	month7	+&lt;BR /&gt;
		a20*	month8	+&lt;BR /&gt;
		a21*	month9	+&lt;BR /&gt;
		a22*	month10	+&lt;BR /&gt;
		a23*	month11	+&lt;BR /&gt;
		a24*	month12	+&lt;BR /&gt;
&lt;BR /&gt;
		a25*	wy	&lt;BR /&gt;
		;&lt;BR /&gt;
		fit lsale_amt /2sls out=out outresid outpredict outest=outest outcov outs=sigma  hccme=1;&lt;BR /&gt;
		instruments&lt;BR /&gt;
		ltv	bath	bed	age	gla1000	lot1000	gla2	lot2	bed2	bath2	age2	tax&lt;BR /&gt;
		month1-month12	&lt;BR /&gt;
		h&lt;BR /&gt;
		/noint;&lt;BR /&gt;
		run;&lt;BR /&gt;
		quit;</description>
      <pubDate>Thu, 01 Oct 2009 22:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-code/m-p/74115#M454</guid>
      <dc:creator>JackSmith</dc:creator>
      <dc:date>2009-10-01T22:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: IML code</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-code/m-p/74116#M455</link>
      <description>One immediate change you can make for efficiency and accuracy is to use the SOLVE function instead of taking the inverse:&lt;BR /&gt;
&lt;BR /&gt;
instead of &lt;BR /&gt;
&lt;BR /&gt;
H2=wnor*inv(i-lamda*wnor)*x*beta;&lt;BR /&gt;
&lt;BR /&gt;
use&lt;BR /&gt;
&lt;BR /&gt;
H2=wnor*solve( i-lamda*wnor,x)*beta;</description>
      <pubDate>Fri, 02 Oct 2009 15:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-code/m-p/74116#M455</guid>
      <dc:creator>Hutch_sas</dc:creator>
      <dc:date>2009-10-02T15:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: IML code</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-code/m-p/74117#M456</link>
      <description>Remember, readers, sending code that can actually be run increases the chances of getting an answer to your problem.&lt;BR /&gt;
&lt;BR /&gt;
Hutch has the right idea, but you don't want to solve with a RHS of x.  Form the quantity z=x*beta, which is a vector, and then use SOLVE.&lt;BR /&gt;
&lt;BR /&gt;
You don't give the dimensions of this problem, which makes it difficult to reproduce what you are doing. However, I'm guessing that wnor is a row vector? Then here is some code similar to yours that we can all actually run:&lt;BR /&gt;
 &lt;BR /&gt;
  proc iml;&lt;BR /&gt;
  nn=100;&lt;BR /&gt;
  p = 24;&lt;BR /&gt;
  x = rannor( j(nn,p,1) );&lt;BR /&gt;
  beta=T(p:1);&lt;BR /&gt;
  lambda=1; &lt;BR /&gt;
  wnor = 1:nn;&lt;BR /&gt;
&lt;BR /&gt;
  I=I(nn);&lt;BR /&gt;
  z = x*beta;&lt;BR /&gt;
  H2=wnor*inv(I-lambda*wnor)*z;&lt;BR /&gt;
  print H2;&lt;BR /&gt;
&lt;BR /&gt;
As Hutch says, the following code improves the efficiency and cuts down on a matrix multiplication:&lt;BR /&gt;
  /* Let  q = inv(I-lambda*wnor)*(x*beta).&lt;BR /&gt;
     Then q = solve( I-lambda*wnor, x*beta )&lt;BR /&gt;
  */&lt;BR /&gt;
  A = I-lambda*wnor;&lt;BR /&gt;
  q = solve( A, z );&lt;BR /&gt;
  H3 = wnor*q;&lt;BR /&gt;
  print H3;&lt;BR /&gt;
&lt;BR /&gt;
If memory is really tight, you can also eliminate the explicity construction of the identity matrix:&lt;BR /&gt;
&lt;BR /&gt;
  /* even less memory...do not explicitly form identity */&lt;BR /&gt;
  A = repeat( -lambda*wnor, nn );&lt;BR /&gt;
  do i = 1 to nn;&lt;BR /&gt;
     A[i,i] = 1 + A[i,i];&lt;BR /&gt;
  end;&lt;BR /&gt;
  free x;   /* you don't don't need this big matrix anymore */&lt;BR /&gt;
  q = solve( A, z );&lt;BR /&gt;
  H4 = wnor*q;&lt;BR /&gt;
  print H4;</description>
      <pubDate>Fri, 02 Oct 2009 17:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-code/m-p/74117#M456</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2009-10-02T17:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: IML code</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-code/m-p/74118#M457</link>
      <description>Thank you for your input.

Message was edited by: JackSmith</description>
      <pubDate>Mon, 05 Oct 2009 21:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-code/m-p/74118#M457</guid>
      <dc:creator>JackSmith</dc:creator>
      <dc:date>2009-10-05T21:08:48Z</dc:date>
    </item>
  </channel>
</rss>

