<?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 dynamically pass columns to proc iml? in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-dynamically-pass-columns-to-proc-iml/m-p/528010#M4509</link>
    <description>&lt;P&gt;This seems like a lot of work to compute the norm of a vector. When you pass a vector to the SVD, the singular value is the (uncorrected) sum of squares of the elements, which is equal to the vector (L2) norm, which you can &lt;A href="https://blogs.sas.com/content/iml/2014/04/07/vector-and-matrix-norms-in-sas.html" target="_self"&gt;compute by using the NORM function&lt;/A&gt;::&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use sashelp.class;
read all var {height weight age} into X;
close;

D = j(ncol(X), 1, .);
norm = j(ncol(X), 1, .);
do i=1 to ncol(X);
   call svd(U, Q, V, X[ ,i]);
   D[i]=Q;
   norm[i] = norm(X[ ,i]); /* more efficient: use NORM of each col */
end;

print D norm;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Even more efficient:&amp;nbsp;the L2 norm is simply the sqrt of the sum of squares of each column, so the most efficient computation is to &lt;A href="https://blogs.sas.com/content/iml/2011/06/06/use-subscript-reduction-operators.html" target="_self"&gt;use the ## subscript reduction operator on each column&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;D = sqrt( X[##, ] ); /* most efficient: sqrt(SSQ) of each column */
print D;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jan 2019 13:10:14 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2019-01-17T13:10:14Z</dc:date>
    <item>
      <title>How to dynamically pass columns to proc iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-dynamically-pass-columns-to-proc-iml/m-p/527955#M4507</link>
      <description>&lt;P&gt;I have data(data1) in following format :&lt;/P&gt;&lt;P&gt;obs&amp;nbsp; |&amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp;|&amp;nbsp; B&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp;|...&lt;/P&gt;&lt;P&gt;&amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; 10&amp;nbsp; |&amp;nbsp; 20 |&amp;nbsp; 40&amp;nbsp; &amp;nbsp;|...&lt;/P&gt;&lt;P&gt;&amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; 05&amp;nbsp; |&amp;nbsp; 24 |&amp;nbsp; 45&amp;nbsp; &amp;nbsp;|...&lt;/P&gt;&lt;P&gt;&amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; 67&amp;nbsp; |&amp;nbsp; 45 |&amp;nbsp; 152 |...&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;I want to pass each columns to call svd which is available in proc iml.&lt;/P&gt;&lt;P&gt;and also want to store values of call svd in another data for further use...&lt;/P&gt;&lt;P&gt;I have tried using ...&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use data1;
read all;
call svd(U, D, V, A);&amp;nbsp;
call svd(U, D1, V, B);&amp;nbsp;
call svd(U, D2, V, C);&amp;nbsp;
:

call symputx("result1", D);
call symputx("result2", D1);
call symputx("result3", D2);
:
quit;

%put &amp;amp;result1
&amp;amp;result2
&amp;amp;result3;

data data2;
array a{*} a1-aN;
a1=&amp;amp;result1;
a2=&amp;amp;result2;
a3=&amp;amp;result3;&lt;BR /&gt;:
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can you help me to run this dynamically?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 09:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-dynamically-pass-columns-to-proc-iml/m-p/527955#M4507</guid>
      <dc:creator>Kaushik1</dc:creator>
      <dc:date>2019-01-17T09:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically pass columns to proc iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-dynamically-pass-columns-to-proc-iml/m-p/527963#M4508</link>
      <description>&lt;P&gt;You can do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
input A B C;
datalines;
10 20 40
05 24 45
67 45 152
;

proc iml;
   use data1;
      read all var _NUM_ into X;
   close data1;

   D=j(nrow(X), 1, .);

   do i=1 to ncol(X);
      call svd(U, temp, V, X[ ,i]);
      D[i]=temp;
   end;

   create data2 var {D};
      append;
   close data2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 10:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-dynamically-pass-columns-to-proc-iml/m-p/527963#M4508</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-17T10:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically pass columns to proc iml?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-dynamically-pass-columns-to-proc-iml/m-p/528010#M4509</link>
      <description>&lt;P&gt;This seems like a lot of work to compute the norm of a vector. When you pass a vector to the SVD, the singular value is the (uncorrected) sum of squares of the elements, which is equal to the vector (L2) norm, which you can &lt;A href="https://blogs.sas.com/content/iml/2014/04/07/vector-and-matrix-norms-in-sas.html" target="_self"&gt;compute by using the NORM function&lt;/A&gt;::&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use sashelp.class;
read all var {height weight age} into X;
close;

D = j(ncol(X), 1, .);
norm = j(ncol(X), 1, .);
do i=1 to ncol(X);
   call svd(U, Q, V, X[ ,i]);
   D[i]=Q;
   norm[i] = norm(X[ ,i]); /* more efficient: use NORM of each col */
end;

print D norm;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Even more efficient:&amp;nbsp;the L2 norm is simply the sqrt of the sum of squares of each column, so the most efficient computation is to &lt;A href="https://blogs.sas.com/content/iml/2011/06/06/use-subscript-reduction-operators.html" target="_self"&gt;use the ## subscript reduction operator on each column&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;D = sqrt( X[##, ] ); /* most efficient: sqrt(SSQ) of each column */
print D;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 13:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-dynamically-pass-columns-to-proc-iml/m-p/528010#M4509</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-01-17T13:10:14Z</dc:date>
    </item>
  </channel>
</rss>

