<?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 to define a matrix using arithmetic operators? in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111540#M856</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Welcome to the SAS/IML language.&amp;nbsp; There are many former MATLAB users on this Support Community, including myself.&lt;/P&gt;&lt;P&gt;To answer your question, curly braces are used to construct a matrix from LITERAL numbers. To build a matrix from EXPRESSIONS, use the horizontal concatenation operator (||) or the vertical concatenation operator, as described in this article:&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://blogs.sas.com/content/iml/2011/02/21/how-to-build-a-vector-from-expressions/" title="http://blogs.sas.com/content/iml/2011/02/21/how-to-build-a-vector-from-expressions/"&gt; How to build a vector from expressions - The DO Loop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For your particular example, use&lt;/P&gt;&lt;P&gt;x = (1/sqrt(5)) || (2/5) || (6**3);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might also enjoy reading about tips to convert a MATLAB program to SAS/IML: &lt;A href="http://blogs.sas.com/content/iml/2011/03/09/translating-a-matlab-program-into-the-sasiml-language-a-case-study/" title="http://blogs.sas.com/content/iml/2011/03/09/translating-a-matlab-program-into-the-sasiml-language-a-case-study/"&gt; Translating a MATLAB program into the SAS/IML language: A case study - The DO Loop&lt;/A&gt;&amp;nbsp; The article includes a very basic MATLAB to IML cheatsheet that might be helpful to you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 15 Aug 2013 09:26:32 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2013-08-15T09:26:32Z</dc:date>
    <item>
      <title>How to define a matrix using arithmetic operators?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111537#M853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is fine to define the following scalars in SAS:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;x1=1/sqrt(5);&lt;/P&gt;&lt;P&gt;x2=2/5;&lt;/P&gt;&lt;P&gt;x3=6**3;&lt;/P&gt;&lt;P&gt;however, syntax errors appear when one tries to define a vector like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;x={1/sqrt(5) 2/5 6**3};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I never experienced a similar problem in Matlab which I use more frequently than SAS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems that there is a similar problem in SAS data step as well. I know that probably one rarely has to use arithmetic operators in defining&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a matrix or in data steps. But I am curious whether this is an easy solution for this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 00:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111537#M853</guid>
      <dc:creator>humenghu</dc:creator>
      <dc:date>2013-08-15T00:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a matrix using arithmetic operators?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111538#M854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For&lt;STRONG&gt; iml&lt;/STRONG&gt; (not im&lt;STRONG&gt;s&lt;/STRONG&gt;) &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/66112/HTML/default/viewer.htm#imlug_langref_sect035.htm" title="http://support.sas.com/documentation/cdl/en/imlug/66112/HTML/default/viewer.htm#imlug_langref_sect035.htm"&gt;SAS/IML(R) 12.3 User's Guide&lt;/A&gt; ( Multiplication Operator, Elementwise:&amp;nbsp;&amp;nbsp; # ) a sample working with vectors&lt;/P&gt;&lt;P&gt;For the datastep &lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/64801/HTML/default/viewer.htm#p19dovt76d4zv4n1h91lg4i12mmm.htm" title="http://support.sas.com/documentation/cdl/en/lrcon/64801/HTML/default/viewer.htm#p19dovt76d4zv4n1h91lg4i12mmm.htm"&gt;SAS(R) 9.4 Language Reference: Concepts&lt;/A&gt; (Syntax for Defining and Referencing an Array)&lt;/P&gt;&lt;P&gt;The major problem looks not to be technical, but getting the syntax and words aligned from one product to another.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 05:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111538#M854</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2013-08-15T05:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a matrix using arithmetic operators?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111539#M855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Hi there, Fellow MATLAB user! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; If you would like to define an array use the following syntax:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* define array*/&lt;BR /&gt;array x{3};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*populate array values*/&lt;BR /&gt;x{1}=1/sqrt(5);&lt;/P&gt;&lt;P&gt;x{2}=2/5;&lt;/P&gt;&lt;P&gt;x{3}=6**3;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* the resultant fields 'x1, x2, x3' remain in the dataset, however the array structure exists only in the data step, unless reassigned */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test2;&lt;/P&gt;&lt;P&gt;set test;&lt;/P&gt;&lt;P&gt;/* reconnect x1 x2 and x3 to an array reference*/&lt;/P&gt;&lt;P&gt;array x{3};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* manipulate array*/&lt;/P&gt;&lt;P&gt;arithmetic = x{2}+x{1}+x{3};&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=test2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 07:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111539#M855</guid>
      <dc:creator>Murray_Court</dc:creator>
      <dc:date>2013-08-15T07:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a matrix using arithmetic operators?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111540#M856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Welcome to the SAS/IML language.&amp;nbsp; There are many former MATLAB users on this Support Community, including myself.&lt;/P&gt;&lt;P&gt;To answer your question, curly braces are used to construct a matrix from LITERAL numbers. To build a matrix from EXPRESSIONS, use the horizontal concatenation operator (||) or the vertical concatenation operator, as described in this article:&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://blogs.sas.com/content/iml/2011/02/21/how-to-build-a-vector-from-expressions/" title="http://blogs.sas.com/content/iml/2011/02/21/how-to-build-a-vector-from-expressions/"&gt; How to build a vector from expressions - The DO Loop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For your particular example, use&lt;/P&gt;&lt;P&gt;x = (1/sqrt(5)) || (2/5) || (6**3);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might also enjoy reading about tips to convert a MATLAB program to SAS/IML: &lt;A href="http://blogs.sas.com/content/iml/2011/03/09/translating-a-matlab-program-into-the-sasiml-language-a-case-study/" title="http://blogs.sas.com/content/iml/2011/03/09/translating-a-matlab-program-into-the-sasiml-language-a-case-study/"&gt; Translating a MATLAB program into the SAS/IML language: A case study - The DO Loop&lt;/A&gt;&amp;nbsp; The article includes a very basic MATLAB to IML cheatsheet that might be helpful to you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 09:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111540#M856</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2013-08-15T09:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a matrix using arithmetic operators?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111541#M857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your reply. After reading the materials, I still have not found a way to solve this particular problem using matrix multiplication. I might try it again later.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 13:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111541#M857</guid>
      <dc:creator>humenghu</dc:creator>
      <dc:date>2013-08-15T13:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a matrix using arithmetic operators?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111542#M858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for providing this example.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 13:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111542#M858</guid>
      <dc:creator>humenghu</dc:creator>
      <dc:date>2013-08-15T13:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a matrix using arithmetic operators?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111543#M859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the tips which are exactly right for my problem. I am happy to learn that there are many Matlab users here in the community.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 13:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111543#M859</guid>
      <dc:creator>humenghu</dc:creator>
      <dc:date>2013-08-15T13:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a matrix using arithmetic operators?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111544#M860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is my example which would be much easier to accomplish in Matlab:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* an example of diagonalizing a symmetric matrix A*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* A wrong attempt to define an orthogonal matrix X*/&lt;/P&gt;&lt;P&gt;*X={-1/3 2/sqrt(5) -2/(3*sqrt(5)), -2/3 0 5/(3*sqrt(5)), 2/3 1/sqrt(5) 4/(3*sqrt(5))} ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*define an orthogonal matrix X using concatenations*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;X=(-1/3 || 2/sqrt(5) || -2/(3*sqrt(5))) // (-2/3 || 0 || 5/(3*sqrt(5))) // ( 2/3 || 1/sqrt(5) || 4/(3*sqrt(5)));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A={2 2 -2, 2 5 -4, -2 -4 5};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;print A "&amp;nbsp; " X [format=5.3];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;print (X`*X) [format=5.3] [label='X´*X'];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;print (eigval(A)) [format=5.3] [label='eigenvalues of A'];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;print (X`*A*X)&amp;nbsp; [format=5.3] [label='X´*A*X'];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 14:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-define-a-matrix-using-arithmetic-operators/m-p/111544#M860</guid>
      <dc:creator>humenghu</dc:creator>
      <dc:date>2013-08-15T14:12:26Z</dc:date>
    </item>
  </channel>
</rss>

