<?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: Multiplication of tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285981#M311542</link>
    <description>&lt;P&gt;Here's an example of temporary arrays:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Sample of lookup using Temporary Arrays*/

data scores;
   input Name $ Test_1 Test_2 Test_3;
   datalines;
Bill 187 97 103
Carlos 156 76 74
Monique 99 102 129
;

data M;
do i=10,20,30,40,50,60,70,100,120,130;
	output;
end;
run;



data want;
array M(10) _temporary_;
if _n_=1 then do j=1 to 10;
set M;
M(j)=i;
end;

set scores;

rank=0;
do i=1 to 10 while (rank=0);
if m(i)&amp;gt; test_3 then rank=i-1;
end;

drop i j;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jul 2016 21:49:15 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-07-20T21:49:15Z</dc:date>
    <item>
      <title>Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285918#M311534</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two SAS tables:&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;type Dur1 Dur2 Dur3&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .4&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;....type Dur1 Dur2 Dur3 Dur4 Dur5....&lt;/P&gt;&lt;P&gt;....&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.....&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new table C with the following feature:&lt;/P&gt;&lt;P&gt;when type = i in B, use the correponding line in A to multiply and apply the last rate (in this case, Dur3's rate) to all the coloumns&amp;nbsp;pass the matching columns.&lt;/P&gt;&lt;P&gt;i.e.&amp;nbsp; for the 1st line in B, C would be&lt;/P&gt;&lt;P&gt;....type Dur1 Dur2 Dur3 Dur4 Dur5....&lt;/P&gt;&lt;P&gt;....&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8*.1&amp;nbsp;&amp;nbsp;&amp;nbsp;3*.2&amp;nbsp;&amp;nbsp;3*.4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9*.4&amp;nbsp;&amp;nbsp;&amp;nbsp;4*.4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;..... &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I would like to change the column names in C--how can I do that in the process of multiplication?&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 17:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285918#M311534</guid>
      <dc:creator>Shiring</dc:creator>
      <dc:date>2016-07-20T17:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285923#M311535</link>
      <description>&lt;P&gt;1. Merge on Type&lt;/P&gt;
&lt;P&gt;2. Rename before merge&lt;/P&gt;
&lt;P&gt;3. Declare arrays&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. Find corresponding rate to mulitply&lt;/P&gt;
&lt;P&gt;5. Multiply&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge tableA(rename=(dur1-dur3 = rate1-rate3))
           tableB;
by type;

array rate(3) rate1-rate3;
array dur(5) dur1-dur5;
array new_dur(5) new_dur1-new_dur5;

do i=1 to dim(dur);
index=min(i, dim(rate));

new_dur(i)=dur(i)*rate(index);
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jul 2016 18:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285923#M311535</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-20T18:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285928#M311536</link>
      <description>I keep getting this error message:&lt;BR /&gt;ERROR: BY variables are not properly sorted on data set tableB.&lt;BR /&gt;My type is character variable b/c it's actually different names. Is that why?&lt;BR /&gt;</description>
      <pubDate>Wed, 20 Jul 2016 18:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285928#M311536</guid>
      <dc:creator>Shiring</dc:creator>
      <dc:date>2016-07-20T18:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285932#M311537</link>
      <description>&lt;P&gt;No. Sort your data before the merge.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 18:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285932#M311537</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-20T18:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285967#M311538</link>
      <description>Instead of doing a loop, are there faster ways to do this? My dataset is quite large, and I actually have multiple table As (different characteristic functions I need to apply to dataset B). So would it be possible to single out the dur array and compute without sorting, merging, or looping? Thank you so much!</description>
      <pubDate>Wed, 20 Jul 2016 20:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285967#M311538</guid>
      <dc:creator>Shiring</dc:creator>
      <dc:date>2016-07-20T20:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285970#M311539</link>
      <description>&lt;P&gt;This is matrix math so possibly IML may be faster.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise I'm not aware of one without a loop. You could try to load a temporary multidimensional array to avoid sorting and merging.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 21:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285970#M311539</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-20T21:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285971#M311540</link>
      <description>I'm downloading IML right now. How to temporarily load a multidimensional array? I just transferred into SAS yesterday from R, so super unfamiliar with the syntax</description>
      <pubDate>Wed, 20 Jul 2016 21:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285971#M311540</guid>
      <dc:creator>Shiring</dc:creator>
      <dc:date>2016-07-20T21:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285980#M311541</link>
      <description>&lt;P&gt;Downloading IML? It's usually included or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you explain more, why do you need to run it multiple times? How big are your datasets. What varies each time?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing with transitioning from R to SAS - it handles big data well out of the box, you don't have to partition datasets. In fact BY processing is incredibly powerful.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're familiar with R, then IML will be more intuitive to you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 21:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285980#M311541</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-20T21:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285981#M311542</link>
      <description>&lt;P&gt;Here's an example of temporary arrays:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Sample of lookup using Temporary Arrays*/

data scores;
   input Name $ Test_1 Test_2 Test_3;
   datalines;
Bill 187 97 103
Carlos 156 76 74
Monique 99 102 129
;

data M;
do i=10,20,30,40,50,60,70,100,120,130;
	output;
end;
run;



data want;
array M(10) _temporary_;
if _n_=1 then do j=1 to 10;
set M;
M(j)=i;
end;

set scores;

rank=0;
do i=1 to 10 while (rank=0);
if m(i)&amp;gt; test_3 then rank=i-1;
end;

drop i j;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 21:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285981#M311542</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-20T21:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285990#M311543</link>
      <description>our corporate app database have multiple SAS parts, including SAS IML, but I only downloaded the prereq part.&lt;BR /&gt;My dataset has about 100,000 data points, and we are thinking about expand it further.&lt;BR /&gt;Right now I am running the multiplication on type, then I need to run it again with gender, length, death tables. so dataset B stays the same, but A changes according to how we partition.&lt;BR /&gt;&lt;BR /&gt;Thank you for your input!</description>
      <pubDate>Wed, 20 Jul 2016 22:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285990#M311543</guid>
      <dc:creator>Shiring</dc:creator>
      <dc:date>2016-07-20T22:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285992#M311544</link>
      <description>&lt;P&gt;100,000 is trivial, you'll be fine with the sort/merge method.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd be surprised if it took more than 10 seconds total on a decent set up.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 22:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/285992#M311544</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-20T22:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/286013#M311545</link>
      <description>&lt;P&gt;Yes. It would be a lot more easy for IML if you make sure Table A and Table B are one to one corresponding .&lt;/P&gt;
&lt;P&gt;(e.g. &amp;nbsp;the first obs of A correspond to the first obs of B, &lt;SPAN&gt;the second&amp;nbsp;obs of A correspond to the second&amp;nbsp;obs of B , .........&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P&gt;You want IML code ?&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 A;
input type Dur1 Dur2 Dur3;
cards;
1       .1      .2       .4
2       .4       .3       0
;
run;
 
data B;
input type Dur1 Dur2 Dur3 Dur4 Dur5;
cards;
1       8       3      3       9        4  
2       8       4      3       9        4 
;
run;  
proc transpose data=a out=temp_a(drop=_:);
by type;
run; 
proc transpose data=b out=temp_b(drop=_:);
by type;
run; 
data temp;
 merge temp_a temp_b(rename=(col1=col2));
 by type;
 want=col1*col2;
run;
proc transpose data=temp out=want(drop=_:) prefix=want;
by type;
var want;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/4149i27438BC00A2367E9/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="x.png" title="x.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 01:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/286013#M311545</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-21T01:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/287496#M311546</link>
      <description>&lt;P&gt;IML coding would be very helpful since I just got the package but have no idea how to code. Do I have to have my matrix to be one to one corresponding tho? Is there a way for matrices to auto-search (to match up the type) and directly compute?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 15:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/287496#M311546</guid>
      <dc:creator>Shiring</dc:creator>
      <dc:date>2016-07-27T15:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/287699#M311547</link>
      <description>&lt;PRE&gt;
OK. Assuming A and B are row to row corresponding .



data A;
input type Dur1 Dur2 Dur3;
cards;
1       .1      .2       .4
2       .4       .3       0
;
run;
 
data B;
input type Dur1 Dur2 Dur3 Dur4 Dur5;
cards;
1       8       3      3       9        4  
2       8       4      3       9        4 
;
run; 
proc iml;
use A(keep=type);
read all var{type};
close;
use A(keep=Dur:);
read all var _num_ into A;
close;
use B(keep=Dur:);
read all var _num_ into B[c=vnames];
close;

ncol_A=ncol(A);
temp=A[,ncol_A];
do i=1 to ncol(B)-ncol_A;
 A=A||temp;
end;

want=type||A#B;

create want from want[c=('type'||vnames)];
append from want;
close;
quit;



&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jul 2016 01:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/287699#M311547</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-28T01:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/287700#M311548</link>
      <description>&lt;PRE&gt;
" Is there a way for matrices to auto-search (to match up the type) and directly compute?"
No. there is no automatic way to do it. You need write code (UNIQUE-LOC skill) to get it.
But for your example, that would be very easy , since TYPE is 1,2,3,4... which represent the 
index of row of matrix .


&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jul 2016 01:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/287700#M311548</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-28T01:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/287913#M311549</link>
      <description>&lt;P&gt;Hi, Ksharp, Thank you for your response! However, A &amp;amp; B are columns from&amp;nbsp;data files. when I try to replace A and B using libname.dataname--there are syntax errors. Also, lib.data2 include B but also other variables that's not in the variable --how&amp;nbsp; can I address that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;Moreover, for my table A : it's 4*8 b/c there are only 4 types. for my table B: there are 500k rows while each row has a type in the type column, thus the dimension is 500k*length(duration). Is there still a way to calculate it?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 19:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/287913#M311549</guid>
      <dc:creator>Shiring</dc:creator>
      <dc:date>2016-07-28T19:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication of tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/288034#M311550</link>
      <description>&lt;PRE&gt;
"when I try to replace A and B using libname.dataname--there are syntax errors. Also, lib.data2 include B but also other variables that's not in the variable --how  can I address that?"

Post your code and Log (Error) Information .



"Moreover, for my table A : it's 4*8 b/c there are only 4 types. for my table B: there are 500k rows while each row has a type in the type column, thus the dimension is 500k*length(duration). Is there still a way to calculate it?"

Then IML still can work on that , but need some more code .
Post some data and the output you want to get to explain your requirement if you really want IML code .
Or just try Data Step .



&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jul 2016 05:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiplication-of-tables/m-p/288034#M311550</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-29T05:09:24Z</dc:date>
    </item>
  </channel>
</rss>

