<?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: Multiplying datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435263#M108117</link>
    <description>&lt;P&gt;Sorry for the formatting issue but thanks for this code.&amp;nbsp; What is the 'inter' dataset?&amp;nbsp; It's not used in the merge.&amp;nbsp; Is that supposed to read 'ds2' or maybe I'm not understanding the logic.&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2018 14:25:08 GMT</pubDate>
    <dc:creator>elsolo21</dc:creator>
    <dc:date>2018-02-08T14:25:08Z</dc:date>
    <item>
      <title>Multiplying datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435242#M108101</link>
      <description>&lt;P&gt;I have two datasets with the following format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset 1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;value1 value2 value3&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Dataset 2:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Parameter&amp;nbsp; &amp;nbsp;amount&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;value1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;value2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;value3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to multiply the two datasets so the 'amount' of value1 in Dataset 2 is multiplied with each value1 in Dataset 1. Output should be:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Dataset 3:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;value1&amp;nbsp; &amp;nbsp;value2&amp;nbsp; value3&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;2.5&amp;nbsp; &amp;nbsp; &amp;nbsp; .7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;1.5&amp;nbsp; &amp;nbsp; &amp;nbsp; .2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Bonus add-on question:&amp;nbsp; I need to then add all the columns so row 1 would equal 7.6, etc. There are about 20 columns so I'd rather not manually build the equation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I think this should be straightforward but I can't wrap my head around it.&lt;/SPAN&gt;&lt;/P&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 13:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435242#M108101</guid>
      <dc:creator>elsolo21</dc:creator>
      <dc:date>2018-02-08T13:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435245#M108104</link>
      <description>&lt;P&gt;Am not typing in test data to test this, post test data in the form of a datastep in future:&lt;/P&gt;
&lt;PRE&gt;proc transpose data=ds2 out=inter prefix=calc;
   by parameter;
   var amount;
run;

data want (drop=calc:);
  merge ds1 ds2;
  array value{3};
  array calc{3};
  do i=1 to 3;
    value{i}=value{i} * calc{i};
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 13:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435245#M108104</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-08T13:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435257#M108112</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input value1 value2 value3;
cards;
   4          6         5
   5          7         3
   3          2         2
   2          4         1
;
run;
 

data b;
input Parameter  $ amount;
cards;
   value1         .5
   value2         .1
   value3         1
;
run;

proc iml;
use a;
read all var _ALL_ into x;
close;
use b;
read all var{amount};
close;
want=(x#amount`)[,+];
create want var {want};
append;
close;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 13:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435257#M108112</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-08T13:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435261#M108115</link>
      <description>&lt;P&gt;Thanks for this solution.&amp;nbsp; Unfortunately, I do not have an applicable license to run 'proc iml' so I cannot test it out.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 14:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435261#M108115</guid>
      <dc:creator>elsolo21</dc:creator>
      <dc:date>2018-02-08T14:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435263#M108117</link>
      <description>&lt;P&gt;Sorry for the formatting issue but thanks for this code.&amp;nbsp; What is the 'inter' dataset?&amp;nbsp; It's not used in the merge.&amp;nbsp; Is that supposed to read 'ds2' or maybe I'm not understanding the logic.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 14:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435263#M108117</guid>
      <dc:creator>elsolo21</dc:creator>
      <dc:date>2018-02-08T14:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435283#M108124</link>
      <description>&lt;P&gt;Apologies, typing to quick and not testing:&lt;/P&gt;
&lt;PRE&gt;proc transpose data=ds2 out=inter prefix=calc;
   by parameter;
   var amount;
run;

data want (drop=calc:);
  merge ds1 inter;
  array value{3};
  array calc{3};
  do i=1 to 3;
    value{i}=value{i} * calc{i};
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Basically transpose the second and merge that one result to all results in other table.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 15:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435283#M108124</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-08T15:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435320#M108146</link>
      <description>&lt;P&gt;long and not very efficient way. use this if you have few columns and few values&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input value1 value2 value3;
cards;
   4          6         5
   5          7         3
   3          2         2
   2          4         1
;
run;
 

data b;
input Parameter  $ amount;
cards;
   value1         .5
   value2         .1
   value3         1
;
run;
data a1;
set a;
col =_n_;
run;
proc sql;
select coalesce(tot1,0) +coalesce(tot2,0)+coalesce(tot3,0) as final_total from 
(select  value1, col,
case when value1 and parameter = 'value1' then value1*amount end as tot1
from a1 cross join b
where calculated tot1 is not missing)x
inner join 
(select  value2,col,
case when value2 and parameter = 'value2' then value2*amount end as tot2
from a1 cross join b
where calculated tot2 is not missing)y
on x.col =y.col
inner join 
(select  value3,col,
case when value3 and parameter = 'value3' then value3*amount end as tot3
from a1 cross join b
where calculated tot3 is not missing)z
on x.col =z.col;
;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 16:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplying-datasets/m-p/435320#M108146</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-02-08T16:16:51Z</dc:date>
    </item>
  </channel>
</rss>

