<?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 Multiplication of tables (large) in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373350#M65211</link>
    <description>&lt;P&gt;Hi, I'm trying to do something similar to what &lt;A href="https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-in-SAS/td-p/125052" target="_self"&gt;this question did&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;The data is in this form;

dataset A (1X3 MATRIX)

COL1 COL2 COL3

4           7     9


Dataset B

COL1 COL2 COL3

5          10     12

9          12     8

16          1     7


The output should be in the form of multiplying all the rows in COL1 in dataset B by COL1 in dataset B ...


OUTPUT TABLE

COL1 COL2 COL3

20       70      108

36       84       72

64       7         63 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The solution given was:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data RESULT;

set A (rename = (COL1-COL3=COLA1-COLA3)); 

drop COLA: COLB:; * drop original columns;

do until (_EOF); * iterate through B for each obs in A;

set B (rename = (COL1-COL3=COLB1-COLB3)) end=_EOF;

COL1=COLA1*COLB1;

COL2=COLA2*COLB2;

COL3=COLA3*COLB3;

output; * output result;

end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;However this is more difficult for me because I have many columns I want to multiply.&amp;nbsp; Is there a way to do this more efficiently than just writing out the formula for each newly computed column?&amp;nbsp; Also, the columns from my two tables have exactly the same column names and are listed in the same order, but don't have names like COL1, COL2,... COL100,&amp;nbsp;and have different names like CANH, CANVH, etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jul 2017 16:06:17 GMT</pubDate>
    <dc:creator>sunless07652</dc:creator>
    <dc:date>2017-07-05T16:06:17Z</dc:date>
    <item>
      <title>Multiplication of tables (large)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373350#M65211</link>
      <description>&lt;P&gt;Hi, I'm trying to do something similar to what &lt;A href="https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-in-SAS/td-p/125052" target="_self"&gt;this question did&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;The data is in this form;

dataset A (1X3 MATRIX)

COL1 COL2 COL3

4           7     9


Dataset B

COL1 COL2 COL3

5          10     12

9          12     8

16          1     7


The output should be in the form of multiplying all the rows in COL1 in dataset B by COL1 in dataset B ...


OUTPUT TABLE

COL1 COL2 COL3

20       70      108

36       84       72

64       7         63 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The solution given was:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data RESULT;

set A (rename = (COL1-COL3=COLA1-COLA3)); 

drop COLA: COLB:; * drop original columns;

do until (_EOF); * iterate through B for each obs in A;

set B (rename = (COL1-COL3=COLB1-COLB3)) end=_EOF;

COL1=COLA1*COLB1;

COL2=COLA2*COLB2;

COL3=COLA3*COLB3;

output; * output result;

end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;However this is more difficult for me because I have many columns I want to multiply.&amp;nbsp; Is there a way to do this more efficiently than just writing out the formula for each newly computed column?&amp;nbsp; Also, the columns from my two tables have exactly the same column names and are listed in the same order, but don't have names like COL1, COL2,... COL100,&amp;nbsp;and have different names like CANH, CANVH, etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 16:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373350#M65211</guid>
      <dc:creator>sunless07652</dc:creator>
      <dc:date>2017-07-05T16:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables (large)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373357#M65212</link>
      <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;PRE&gt;data A;
  input CANH CANVH SOMETHING_ELSE;
  cards;
4           7     9
;

Data B;
  input CANH CANVH SOMETHING_ELSE;
  cards;
5          10     12
9          12     8
16          1     7
;

proc sql noprint;
  select catt(name,'=_',name),
         catt('_',name)
    into :renames separated by ' ',
         :array separated by ' '
      from dictionary.columns
        where libname=upcase('work') and
              memname=upcase('A')
          order by varnum
  ;
quit;

data want (drop=_:);
  if _n_ eq 1 then set a (rename=(&amp;amp;renames.));
  set b;
  array a(*)  &amp;amp;array.;
  array b(*) CANH--SOMETHING_ELSE;
  do _n_=1 to dim(b);
    b(_n_)=b(_n_)*a(_n_);
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 17:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373357#M65212</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-05T17:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables (large)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373396#M65213</link>
      <description>&lt;P&gt;I would suggest skipping all the renames.&amp;nbsp; Although it might be possible to come up with a variable list instead of spelling out all the names, let's assume for now that you are going to spell them out once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;if _n_=1 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; array vars&amp;nbsp; &amp;nbsp;{100}&amp;nbsp; put the list of 100 names here;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; array coeffs {100} _temporary_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do _i_ = 1 to 100;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; coeffs{_i_} = vars{_i_};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;set b;&lt;/P&gt;
&lt;P&gt;do _i_ = 1 to 100;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; vars{_i_} = vars{_i_} * coeffs{_i_};&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop _i_;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Copy from the data set A to a temporary array.&amp;nbsp; Temporary array values are automatically retained, and don't require dropping since they are not variables.&amp;nbsp; Then the multiplication is straightforward.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 18:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373396#M65213</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-05T18:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables (large)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373627#M65231</link>
      <description>&lt;P&gt;It is best for IML code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
  input CANH CANVH SOMETHING_ELSE;
  cards;
4           7     9
;

Data B;
  input CANH CANVH SOMETHING_ELSE;
  cards;
5          10     12
9          12     8
16          1     7
;

proc iml;
use a;
read all var _all_ into x;
close;
use b;
read all var _all_ into y;
close;

z=x#y;

create want from z;
append from z;
close;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jul 2017 12:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373627#M65231</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-07-06T12:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables (large)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373650#M65240</link>
      <description>&lt;P&gt;Thanks, that looks great but unfortunately my version of SAS EG doesn't have SML.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 13:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiplication-of-tables-large/m-p/373650#M65240</guid>
      <dc:creator>sunless07652</dc:creator>
      <dc:date>2017-07-06T13:41:17Z</dc:date>
    </item>
  </channel>
</rss>

