<?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 User-defined module with multiple outputs? in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/User-defined-module-with-multiple-outputs/m-p/37536#M176</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can't list multiple matrices on the RETURN statement (that's MATLAB syntax) but you can return as many values as you want by writing a subroutine module instead of a function module.&lt;/P&gt;&lt;P&gt;For an example, see the bottom of p. 2 of &lt;A href="http://support.sas.com/resources/papers/proceedings10/329-2010.pdf"&gt;http://support.sas.com/resources/papers/proceedings10/329-2010.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Incidentally, you can do this because &lt;A href="http://blogs.sas.com/content/iml/2011/02/07/passing-arguments-by-reference-an-efficient-choice/"&gt;SAS/IML passes arguments by reference&lt;/A&gt;, not by value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SAS/IML convention is that output arguments are listed first, so your module might look like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;start ols (beta, residual, y,x); &lt;/P&gt;&lt;P&gt;&amp;nbsp; beta=inv(x`*x)*(x`*y);&lt;/P&gt;&lt;P&gt;&amp;nbsp; residual=y-x*beta;&lt;/P&gt;&lt;P&gt;finish ols;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* define data */&lt;/P&gt;&lt;P&gt;x= { 1 1 1,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 2 4,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 3 9,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 4 16,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 5 25,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 6 36,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 7 49,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 8 64 }; &lt;/P&gt;&lt;P&gt;y= {3.929,5.308,7.239,9.638,12.866,17.069,23.191,31.443};&lt;/P&gt;&lt;P&gt;/* call module */&lt;/P&gt;&lt;P&gt;run ols(b, r, y, x);&lt;/P&gt;&lt;P&gt;print b, r;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Jan 2012 20:11:59 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2012-01-24T20:11:59Z</dc:date>
    <item>
      <title>User-defined module with multiple outputs?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/User-defined-module-with-multiple-outputs/m-p/37535#M175</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, there:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am wondering if I can define some modules with mutliple outputs in IML. For example, I want to write a simple module to do linear regression and output both the estimated coefficients and residual series. Can I write it in this way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;start ols (y,x);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;beta=inv(x`*x)*(x`*y);&lt;/P&gt;&lt;P&gt;residual=y-x*beta;&lt;/P&gt;&lt;P&gt;return (beta,residual);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;finish ols. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I want to use it, can I write a line in the main body of code like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;{beta,residual}=ols(y_data,x_data).&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't find any sample online. Some subroutines following the "call" keyword can give multiple outputs, however, the output names are prefixed. I want to be able to control the output names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jan 2012 19:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/User-defined-module-with-multiple-outputs/m-p/37535#M175</guid>
      <dc:creator>bigbigben</dc:creator>
      <dc:date>2012-01-24T19:59:38Z</dc:date>
    </item>
    <item>
      <title>User-defined module with multiple outputs?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/User-defined-module-with-multiple-outputs/m-p/37536#M176</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can't list multiple matrices on the RETURN statement (that's MATLAB syntax) but you can return as many values as you want by writing a subroutine module instead of a function module.&lt;/P&gt;&lt;P&gt;For an example, see the bottom of p. 2 of &lt;A href="http://support.sas.com/resources/papers/proceedings10/329-2010.pdf"&gt;http://support.sas.com/resources/papers/proceedings10/329-2010.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Incidentally, you can do this because &lt;A href="http://blogs.sas.com/content/iml/2011/02/07/passing-arguments-by-reference-an-efficient-choice/"&gt;SAS/IML passes arguments by reference&lt;/A&gt;, not by value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SAS/IML convention is that output arguments are listed first, so your module might look like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;start ols (beta, residual, y,x); &lt;/P&gt;&lt;P&gt;&amp;nbsp; beta=inv(x`*x)*(x`*y);&lt;/P&gt;&lt;P&gt;&amp;nbsp; residual=y-x*beta;&lt;/P&gt;&lt;P&gt;finish ols;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* define data */&lt;/P&gt;&lt;P&gt;x= { 1 1 1,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 2 4,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 3 9,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 4 16,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 5 25,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 6 36,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 7 49,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 8 64 }; &lt;/P&gt;&lt;P&gt;y= {3.929,5.308,7.239,9.638,12.866,17.069,23.191,31.443};&lt;/P&gt;&lt;P&gt;/* call module */&lt;/P&gt;&lt;P&gt;run ols(b, r, y, x);&lt;/P&gt;&lt;P&gt;print b, r;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jan 2012 20:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/User-defined-module-with-multiple-outputs/m-p/37536#M176</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2012-01-24T20:11:59Z</dc:date>
    </item>
  </channel>
</rss>

