<?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 How to Wrap optimization call inside a sas iml module? in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-Wrap-optimization-call-inside-a-sas-iml-module/m-p/368464#M3535</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
	x = {1,1,1,2,2,2,3,3,3};
	y = {0.5,0.6,0.5,1,1.2,1,1.5,1.5,1.6};
Start reg(x,y);
	Start SSE(alpha) global(x,y);
		m = nrow(y);
		res = j(1,m,0);
		res = ((y - (alpha[1] + x*alpha[2:ncol(alpha)]))##2)`;
		return(res);
	finish SSE;
	alpha = {0.5 30};
	m1 = nrow(y);
	optn = m1||2;
	con = {0 0,
		   . 1};
	call NLPLM(rc,xres,"SSE",alpha,optn,con);
	print rc;
	print xres;
return(xres);
finish reg;
	xres = reg(x,y);
	m1 = nrow(y);	
	xd = (j(m1,1,1) || x);
	sol = solve(xd`*xd,xd`*y); /*checking*/
	print sol;
	
quit;


		&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to create a Non negative least squares inside proc iml as above. I want to wrap the nlplm call inside a modue becuase the values of x and y changes in my program (ie, i do reg on diferent partitions of orginal data). I get error for this program because x and y are not defined in the module SSE needed for nlplm. How do i go about this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Jun 2017 19:38:13 GMT</pubDate>
    <dc:creator>karthick_gopal</dc:creator>
    <dc:date>2017-06-19T19:38:13Z</dc:date>
    <item>
      <title>How to Wrap optimization call inside a sas iml module?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-Wrap-optimization-call-inside-a-sas-iml-module/m-p/368464#M3535</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
	x = {1,1,1,2,2,2,3,3,3};
	y = {0.5,0.6,0.5,1,1.2,1,1.5,1.5,1.6};
Start reg(x,y);
	Start SSE(alpha) global(x,y);
		m = nrow(y);
		res = j(1,m,0);
		res = ((y - (alpha[1] + x*alpha[2:ncol(alpha)]))##2)`;
		return(res);
	finish SSE;
	alpha = {0.5 30};
	m1 = nrow(y);
	optn = m1||2;
	con = {0 0,
		   . 1};
	call NLPLM(rc,xres,"SSE",alpha,optn,con);
	print rc;
	print xres;
return(xres);
finish reg;
	xres = reg(x,y);
	m1 = nrow(y);	
	xd = (j(m1,1,1) || x);
	sol = solve(xd`*xd,xd`*y); /*checking*/
	print sol;
	
quit;


		&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to create a Non negative least squares inside proc iml as above. I want to wrap the nlplm call inside a modue becuase the values of x and y changes in my program (ie, i do reg on diferent partitions of orginal data). I get error for this program because x and y are not defined in the module SSE needed for nlplm. How do i go about this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 19:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-Wrap-optimization-call-inside-a-sas-iml-module/m-p/368464#M3535</guid>
      <dc:creator>karthick_gopal</dc:creator>
      <dc:date>2017-06-19T19:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to Wrap optimization call inside a sas iml module?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-Wrap-optimization-call-inside-a-sas-iml-module/m-p/368469#M3536</link>
      <description>&lt;P&gt;First, you need to realize that &lt;A href="http://blogs.sas.com/content/iml/2014/04/21/local-functions-not-in-the-sasiml-langauge.html" target="_self"&gt;there is NO SUCH THING as a "local" or "nested" module.&lt;/A&gt;&amp;nbsp;All modules are global in scope.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, you might want to review &lt;A href="http://blogs.sas.com/content/iml/2013/04/29/understanding-local-and-global-variables-in-the-sasiml-language.html" target="_self"&gt;the rules for local and global symbols in a module.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Together, these rules imply that you can run the program like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
Start SSE(alpha) global(g_x,g_y);
	m = nrow(g_y);
	res = j(1,m,0);
	res = ((g_y - (alpha[1] + g_x*alpha[2:ncol(alpha)]))##2)`;
	return(res);
finish SSE;

Start reg(x,y) global(g_x, g_y);
   g_x = x; g_y = y;  /* copy into global symbols */
	alpha = {0.5 30};
	m1 = nrow(y);
	optn = m1||2;
	con = {0 0,
		   . 1};
	call NLPLM(rc,xres,"SSE",alpha,optn,con);
	print rc;
	print xres;
return(xres);
finish reg;

x = {1,1,1,2,2,2,3,3,3};
y = {0.5,0.6,0.5,1,1.2,1,1.5,1.5,1.6};
xres = reg(x,y);
m1 = nrow(y);	
xd = (j(m1,1,1) || x);
sol = solve(xd`*xd,xd`*y); /*checking*/
print sol;
	&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Jun 2017 20:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-Wrap-optimization-call-inside-a-sas-iml-module/m-p/368469#M3536</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-06-19T20:00:16Z</dc:date>
    </item>
  </channel>
</rss>

