<?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: Show all the possible distinct combinations from records in 4 different datasets in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828504#M5848</link>
    <description>Other variables in the datasets refer to dimension and cost. Those a1,b2,c4,etc values are ProductIDs which I am planning to then rejoin with the Size and Cost variables, trying to figure out all the possible combinations for shipment, and then pulling out the 10-15 optimal ones.&lt;BR /&gt;&lt;BR /&gt;The cartesian join would actually be across more datasets, around 10 different products, e.g. A1,A2,B,C,D,E,F1,F2,F3,G. And the average dataset would have between 15 to 35 records (product IDs) each.&lt;BR /&gt;</description>
    <pubDate>Fri, 12 Aug 2022 19:44:42 GMT</pubDate>
    <dc:creator>zpc</dc:creator>
    <dc:date>2022-08-12T19:44:42Z</dc:date>
    <item>
      <title>Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828454#M5840</link>
      <description>&lt;P&gt;I have 4 separate datasets (A, B, C and D) with a different number of records in each.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;B&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;C&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;D&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;b1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;c1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;d1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;b2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;c2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;d2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;b3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;c3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;d3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a4&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;b4&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;d4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a5&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;b5&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a6&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to produce a single dataset which would show all the possible distinct combinations, pulling 2 records at a time from the A dataset, and one at a time from the other datasets.&amp;nbsp; Something like :&lt;/P&gt;&lt;TABLE border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Part1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Part2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Part3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Part4&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Part5&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a1&lt;/TD&gt;&lt;TD&gt;a2&lt;/TD&gt;&lt;TD&gt;b1&lt;/TD&gt;&lt;TD&gt;c1&lt;/TD&gt;&lt;TD&gt;d1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a1&lt;/TD&gt;&lt;TD&gt;a2&lt;/TD&gt;&lt;TD&gt;b2&lt;/TD&gt;&lt;TD&gt;c1&lt;/TD&gt;&lt;TD&gt;d1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a1&lt;/TD&gt;&lt;TD&gt;a2&lt;/TD&gt;&lt;TD&gt;b1&lt;/TD&gt;&lt;TD&gt;c2&lt;/TD&gt;&lt;TD&gt;d1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a1&lt;/TD&gt;&lt;TD&gt;a2&lt;/TD&gt;&lt;TD&gt;b1&lt;/TD&gt;&lt;TD&gt;c1&lt;/TD&gt;&lt;TD&gt;d2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obviously this is a simplified version of the problem I have.&amp;nbsp; I'm not familiar with SAS/IML but after exploring the possible solutions, IML articles keep showing up as a great option when dealing with combinations.&amp;nbsp; Is it ?&amp;nbsp; I've read a few of Rick Wicklin's articles on dealing with combinations, but they usually show a single list of items to work from.&amp;nbsp; In my case, I have 4 list of items (A, B, C and D) and their lenght are all different, so they wouldn't form a typical matrix.&amp;nbsp; Would a DATA step be a better solution ?&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>Fri, 12 Aug 2022 13:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828454#M5840</guid>
      <dc:creator>zpc</dc:creator>
      <dc:date>2022-08-12T13:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828456#M5841</link>
      <description>&lt;P&gt;A Cartesian join in PROC SQL can do this, but ... caution ... it can result in very large data sets that take a very long time to create.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is example code using data set SASHELP.CLASS (since I don't have your data sets A B C D)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table abc as select a1.name,a2.name as name2,b.sex,c.height
        from sashelp.class as a1,sashelp.class as a2,sashelp.class as b,sashelp.class as c;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Working form a very small data set like SASHELP.CLASS which has 19 records, this Cartesian join produces a data set with 130,321 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You state: "&lt;SPAN&gt;Obviously this is a simplified version of the problem I have." I think your are going to wind up with a humongous data set that will take a very long time to create, and perhaps&amp;nbsp;you need to re-consider doing this. Please explain why you need all possible combinations.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 13:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828456#M5841</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-12T13:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828458#M5842</link>
      <description>&lt;P&gt;Let's assume that A through D are the names of the data sets, and Part1 through Part4 are the names of the fields within.&amp;nbsp; (That's actually critical information for writing a program.)&amp;nbsp; It seems like SQL should do the trick:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A1 (rename=(part1=part1a)) &lt;BR /&gt;     A2 (rename=(part1=part1b));
   set A;
run;

proc sql;
   select * from A1, A2, B, C, D;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It also sounds like you would want to remove observations having part1a = part1b, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;suggests.&amp;nbsp; (You beat me to it by 23 seconds!)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 13:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828458#M5842</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-08-12T13:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828462#M5843</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;nice.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given the OPs posted want data set, you may want to limit the data so&amp;nbsp;&lt;CODE class=" language-sas"&gt;part1a ne part1b&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input Part1 $;
datalines;
a1
a2
a3
a4
a5
a6
;

data b;
input Part2 $;
datalines;
b1
b2
b3
b4
b5
;

data c;
input Part3 $;
datalines;
c1
c2
c3
;

data d;
input Part4 $;
datalines;
d1
d2
d3
d4
;

data A1 (rename=(part1=part1a)) 
     A2 (rename=(part1=part1b));
   set A;
run;

proc sql;
   select * from A1, A2, B, C, D
   where part1a ne part1b;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Aug 2022 13:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828462#M5843</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-12T13:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828466#M5844</link>
      <description>&lt;P&gt;You can certainly do it in SAS ML, but as others have pointed out, Cartesian joins are available by using several methods in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The tricky part is that you seem to want to treat the A variable differently than B, C, and D. When you say you want distinct pairwise combinations, do you mean that&amp;nbsp;you want (a1,a2), but not (a2,a1)?&lt;/P&gt;
&lt;P&gt;Your example does not specify.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want pairwise combinations of the A values, then take the Cartesian join of the A data and then form the Cartesian join of that data with the join of the B, C, and D variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following PROC IML program uses the ALLCOMB function to get the pairwise combinations for A and uses the EXPANDGRID function to get the Cartesian join for B, C, and D.&amp;nbsp; A loop then writes the combinations to a data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
length A $2;
input A @@;
datalines;
a1 a2 a3 a4 a5 a6
;
data B;
length B $2;
input B @@;
datalines;
b1 b2 b3 b4 b5
;
data C;
length C $2;
input C @@;
datalines;
c1 c2 c3
;
data D;
length D $2;
input D @@;
datalines;
d1 d2 d3 d4
;

proc iml;
use A; read all var "A"; close;
/* pairs of values in A */
Aindex = allcomb(nrow(A), 2);
A1 = A[Aindex[,1]];
A2 = A[Aindex[,2]];
*print AIndex A1 A2;

/* Cartesian product of the other variables */
use B; read all var "B"; close;
use C; read all var "C"; close;
use D; read all var "D"; close;

AllBCD = ExpandGrid(B,C,D);
/* for each pair of A values, write the Cartesian product for BCD */
result = A1[1] || A2[1] || AllBCD[1,];  /* tell IML it is a character matrix */
create AllComb from result[c={A1 A2 B C D}];
n = nrow(AllBCD);
do i = 1 to nrow(AIndex);
   result = j(n,1,A1[i]) || j(n,1,A2[i]) || AllBCD;
   append from result;
end;
close;
QUIT;

proc print data=AllComb(obs=30);
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that is not what you want, then please explain further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 14:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828466#M5844</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-08-12T14:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828497#M5845</link>
      <description>Wow thank you Rick, yes do I need to avoid duplicating results, i.e. (a1,a2) means the same to me than (a2,a1). &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; 's solution is simpler but I do get duplicate combinations. Testing both solution, I get 1800 records with the proc sql vs 900 using your proc iml script.&lt;BR /&gt;&lt;BR /&gt;From reading the documentation, since SAS/IML keeps the results in memory, the risk is to run out of RAM, correct ?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 12 Aug 2022 18:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828497#M5845</guid>
      <dc:creator>zpc</dc:creator>
      <dc:date>2022-08-12T18:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828500#M5846</link>
      <description>&lt;P&gt;No need to create copies of table A. Simply name it twice in SQL. To eliminate duplicate combinations you can arbitrarly pick the one where the first part is greater than the second.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   select * from A(rename=part1=part1a), A(rename=part1=part1b), B, C, D
   where part1a gt part1b;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Aug 2022 18:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828500#M5846</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-08-12T18:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828501#M5847</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;since SAS/IML keeps the results in memory, the risk is to run out of RAM, correct?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;True. But as Paige pointed out, this entire method (Cartesian join) will become problematic long before you run out of RAM. His questions are important: Why do you want to do this? What problem are you trying to solve?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In real data, the number of possible combinations of values is usually far greater than the&amp;nbsp;combinations that are realized. For example, you might have data for the countries&lt;BR /&gt;&lt;STRONG&gt;USA, Canada, UK&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;and the political parties&lt;BR /&gt;&lt;STRONG&gt;Democrat, Republican, Liberal, Conservative, New Democrat, Bloc Quebecois, Labour, Scottish National, ...&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;but most of the levels in a full Cartesian join of Country*Party are not going to appear in the data.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 19:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828501#M5847</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-08-12T19:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828504#M5848</link>
      <description>Other variables in the datasets refer to dimension and cost. Those a1,b2,c4,etc values are ProductIDs which I am planning to then rejoin with the Size and Cost variables, trying to figure out all the possible combinations for shipment, and then pulling out the 10-15 optimal ones.&lt;BR /&gt;&lt;BR /&gt;The cartesian join would actually be across more datasets, around 10 different products, e.g. A1,A2,B,C,D,E,F1,F2,F3,G. And the average dataset would have between 15 to 35 records (product IDs) each.&lt;BR /&gt;</description>
      <pubDate>Fri, 12 Aug 2022 19:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828504#M5848</guid>
      <dc:creator>zpc</dc:creator>
      <dc:date>2022-08-12T19:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828508#M5849</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289174"&gt;@zpc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Other variables in the datasets refer to dimension and cost. Those a1,b2,c4,etc values are ProductIDs which I am planning to then rejoin with the Size and Cost variables, trying to figure out all the possible combinations for shipment, and then pulling out the 10-15 optimal ones.&lt;BR /&gt;&lt;BR /&gt;The cartesian join would actually be across more datasets, around 10 different products, e.g. A1,A2,B,C,D,E,F1,F2,F3,G. And the average dataset would have between 15 to 35 records (product IDs) each.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Even if there are just 15 records in each data set, and 10 data sets, that means you have 15**10 elements in a Cartesian join, which is over 576 billion records. Don't even attempt to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There must be a better way. But this is really a weak explanation of what you are trying to do ... providing almost no detail on "... pulling out the 10-15 optimal ones". It seems to me that you should be selecting likely candidates (regardless of whether or not they are "optimal") rather than&lt;/P&gt;
&lt;P&gt;all possible candidates, and determining which ones are optimal. But again, you have given us almost nothing to go on here, its really hard to propose any detailed way of doing things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 20:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828508#M5849</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-12T20:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Show all the possible distinct combinations from records in 4 different datasets</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828533#M5850</link>
      <description>I didn't realize how big this could grow. Like I mentioned I do need to take into account other variables as the size and cost which would limit the amount of possible combinations allowed. I've been searching through the forum and I think my question has a lot of similarities with the knapsack problem. Found this post that might be useful:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Variation-of-Knapsack-Problem/td-p/569457" target="_blank"&gt;https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Variation-of-Knapsack-Problem/td-p/569457&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 12 Aug 2022 22:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Show-all-the-possible-distinct-combinations-from-records-in-4/m-p/828533#M5850</guid>
      <dc:creator>zpc</dc:creator>
      <dc:date>2022-08-12T22:06:08Z</dc:date>
    </item>
  </channel>
</rss>

