<?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 ask a question in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/765251#M5634</link>
    <description>&lt;P&gt;Because ListShape handles lists of lists, you can even specify each row of the matrix that you want to construct with it own list - this may seem a more natural syntax.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;z = ListShape( [ [5, -sqrt(2)], [-sqrt(2), 3] ], 2, 2);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will give&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;         z

        5 -1.414214
-1.414214         3&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 01 Sep 2021 08:11:46 GMT</pubDate>
    <dc:creator>IanWakeling</dc:creator>
    <dc:date>2021-09-01T08:11:46Z</dc:date>
    <item>
      <title>How to use a formula or expression in a matrix cell</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764226#M5624</link>
      <description>&lt;P&gt;I have a question about IML but I keep getting an error about post flooding. What is it? How can I post my question?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 18:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764226#M5624</guid>
      <dc:creator>JohnKeighley</dc:creator>
      <dc:date>2021-08-28T18:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to ask a question</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764232#M5625</link>
      <description>It can happen when you edit/re-edit a post multiple times. But I don't see any of your attempts in our spam quarantine. And you managed to post this question, so I'd say please just try again.</description>
      <pubDate>Thu, 26 Aug 2021 15:04:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764232#M5625</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-08-26T15:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to ask a question</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764234#M5626</link>
      <description>&lt;P&gt;I tried to post the question multiple times. It alternative between saying fix highlighted problem, I didn't see a highlighted problem and the post flood.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think my question is likely a very simple question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had text, sas code, and log results in the post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 15:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764234#M5626</guid>
      <dc:creator>JohnKeighley</dc:creator>
      <dc:date>2021-08-26T15:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to ask a question</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764236#M5627</link>
      <description>&lt;P&gt;It might not hurt to consider how much stuff you were posting and what format.&lt;/P&gt;
&lt;P&gt;Were you providing code examples as text in the text or code boxes (opened on the forum with the &amp;lt;/&amp;gt; and 'running man' icons above message window)?&lt;/P&gt;
&lt;P&gt;Data examples should be provided as a data step in the text or code box. Other forms of copy/paste tables are likely to be full of other "stuff" and might cause problems as the forum window tries to interpret that.&lt;/P&gt;
&lt;P&gt;Example data should be that, enough to show the issue, not 1000's of lines.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 15:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764236#M5627</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-26T15:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to ask a question</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764240#M5628</link>
      <description>&lt;P&gt;I am trying to type values into a matrix in proc iml. A simple 2x2 matrix and I want the negative square root of 2 for the off-diagonal elements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried 4 different ways to find the square root and none worked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can and have given up on doing that in proc iml so I created two variables in the data step and read that dataset into proc iml but I don't think that I should need to do this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 15:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764240#M5628</guid>
      <dc:creator>JohnKeighley</dc:creator>
      <dc:date>2021-08-26T15:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to ask a question</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764461#M5629</link>
      <description>Post you question here . and calling out &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;</description>
      <pubDate>Fri, 27 Aug 2021 13:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764461#M5629</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-08-27T13:41:19Z</dc:date>
    </item>
    <item>
      <title>How to use a formula or expression in a matrix cell</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764462#M5630</link>
      <description>&lt;P&gt;I suspect you need to read the article &lt;A href="https://blogs.sas.com/content/iml/2011/02/21/how-to-build-a-vector-from-expressions.html" target="_self"&gt;"How to build a vector from expressions,"&lt;/A&gt;&amp;nbsp;which explains what you can and cannot do with matrix literals. Based on your description, it sounds like you tried something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
val = -sqrt(2);
/* you can't put a variable inside a matrix literal.
   For example, this DOES NOT work: */
A = {1   val, 
     val 2};   /* ERROR: Mixing character with numeric in matrix literal */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead, use the matrix concatenation operators to build your 2x2 matrix:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
val = -sqrt(2);
A = (1   || val) //
    (val || 2);
print A;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 17:45:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764462#M5630</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-08-31T17:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to ask a question</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764641#M5631</link>
      <description>&lt;P&gt;Thank you Rick.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are my attempts which didn't work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
reset print;

B={5 -sqrt(2), -sqrt(2) 3};
C={5 -2##0.5, -2##0.5 3};
D={5 -1*sqrt(2), -1*sqrt(2) 3};
E={5 (-1*sqrt(2)), (-1*sqrt(2)) 3};
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Fortunately, there is always an way to get things done so I used this method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data one;
  input x1 x2;
  if x1=-2 then x1=-sqrt(2);
  if x2=-2 then x2=-sqrt(2);
datalines;
5 -2
-2 2
;
run;

proc print;
run;

proc iml;
  reset print;  * I don't typically use this option but set it for this example;
  use work.one;
  read all var _num_ into X;

  * additional code;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 17:41:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/764641#M5631</guid>
      <dc:creator>JohnKeighley</dc:creator>
      <dc:date>2021-08-28T17:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to ask a question</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/765004#M5632</link>
      <description>&lt;P&gt;Expressions are allowed when creating a list, so I thought that another way to get what you want is to use a helper function to extract the numeric data from a list, and convert it into a single matrix.&amp;nbsp; Essentially this is generalizing the shape function to a list.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
/* Concatenate all numeric items in a list and return the reshaped data in the form
   of a nr*nc matrix. Sublists upto a depth of maxdepth are searched for data. */
start ListShape(L, nr, nc);
   if type(L) ^= 'L' then return;
   maxdepth = 20;
   /* idx used as loop variable at each depth, ni is the list length at each depth */
   idx = j(1, maxdepth, 0);
   ni = j(1, maxdepth, 0);
   d = 1;  /* the current depth in the list */
   do until( d = 0 );
	 if idx[d] = 0
       then if d = 1
         then ni[d] = ListLen( L );
         else ni[d] = ListLen( ListGetSubItem( L, idx[1:(d-1)]) );
	 idx[d] = idx[d] + 1;
     if idx[d] &amp;lt;= ni[d] then do;
	   x = ListGetSubItem( L, idx[1:d] );
       if type(x) = 'N' then do;
	     /* glue all data together into a column vector y */
	     y = y // shape(x, nrow(x)#ncol(x) );
       end; else if type(x) = 'L' then d = d + 1; /* item is a list so move deeper */
     end; else do;
	   idx[d] = 0;
	   d = d - 1; /* move up the list one level */
	 end;
   end;
   return(shape(y, nr, nc));
finish;

z = ListShape( [5##2, -sqrt(2), -sqrt(2), 1:3], 3, 2);
print z;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which produces:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;         z

       25 -1.414214
-1.414214         1
        2         3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The ListShape function is effectively using concatenation within a loop, which will not be efficient with large amounts of data, but should be fine for the small examples given above.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 09:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/765004#M5632</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2021-08-31T09:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to ask a question</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/765126#M5633</link>
      <description>&lt;P&gt;Interesting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;John&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 17:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/765126#M5633</guid>
      <dc:creator>JohnKeighley</dc:creator>
      <dc:date>2021-08-31T17:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to ask a question</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/765251#M5634</link>
      <description>&lt;P&gt;Because ListShape handles lists of lists, you can even specify each row of the matrix that you want to construct with it own list - this may seem a more natural syntax.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;z = ListShape( [ [5, -sqrt(2)], [-sqrt(2), 3] ], 2, 2);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will give&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;         z

        5 -1.414214
-1.414214         3&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 08:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-use-a-formula-or-expression-in-a-matrix-cell/m-p/765251#M5634</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2021-09-01T08:11:46Z</dc:date>
    </item>
  </channel>
</rss>

