<?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 Cartesian Product within Groups without Repetition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-within-Groups-without-Repetition/m-p/430868#M106517</link>
    <description>&lt;P&gt;I have a dataset with more than one record per customer. I want to get output in which for every customer, there is every possible combinations between its records, however without repetition, i.e. once combining record 1 and 2 for customer 111 the combination 2 and 1 should not be added as it is considered repetition. Similarly records 1 and 1 should not be combined as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this example data, the output should result in 6 rows. However, I've only got it to the point in which repetitions are included and the output is 8 rows.&lt;/P&gt;&lt;PRE&gt;data test;
input Cust_ID Record_ID ;
datalines;
111 1 
111 2 
222 3 
222 4 
222 5 
;

proc sql;                  
  create table test2 as    
    select a.*, b.Record_ID as ID2                           
    from test a 
	left join test b
	on a.Cust_ID = b.Cust_ID and a.record_id ^= b.record_id ;              
quit;  &lt;/PRE&gt;</description>
    <pubDate>Thu, 25 Jan 2018 12:14:07 GMT</pubDate>
    <dc:creator>KonstantinVasil</dc:creator>
    <dc:date>2018-01-25T12:14:07Z</dc:date>
    <item>
      <title>Cartesian Product within Groups without Repetition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-within-Groups-without-Repetition/m-p/430868#M106517</link>
      <description>&lt;P&gt;I have a dataset with more than one record per customer. I want to get output in which for every customer, there is every possible combinations between its records, however without repetition, i.e. once combining record 1 and 2 for customer 111 the combination 2 and 1 should not be added as it is considered repetition. Similarly records 1 and 1 should not be combined as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this example data, the output should result in 6 rows. However, I've only got it to the point in which repetitions are included and the output is 8 rows.&lt;/P&gt;&lt;PRE&gt;data test;
input Cust_ID Record_ID ;
datalines;
111 1 
111 2 
222 3 
222 4 
222 5 
;

proc sql;                  
  create table test2 as    
    select a.*, b.Record_ID as ID2                           
    from test a 
	left join test b
	on a.Cust_ID = b.Cust_ID and a.record_id ^= b.record_id ;              
quit;  &lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2018 12:14:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-within-Groups-without-Repetition/m-p/430868#M106517</guid>
      <dc:creator>KonstantinVasil</dc:creator>
      <dc:date>2018-01-25T12:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: Cartesian Product within Groups without Repetition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-within-Groups-without-Repetition/m-p/430872#M106518</link>
      <description>&lt;P&gt;I'm not sure but I have the feeling that you need replace line:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on a.Cust_ID = b.Cust_ID and a.record_id ^= b.record_id ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on a.Cust_ID = b.Cust_ID and a.record_id &amp;lt; b.record_id ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2018 12:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-within-Groups-without-Repetition/m-p/430872#M106518</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-01-25T12:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Cartesian Product within Groups without Repetition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-within-Groups-without-Repetition/m-p/430880#M106524</link>
      <description>&lt;P&gt;Running your code as is result into 6 records (not 8),&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but in two of them ID2 is missing.&lt;/P&gt;
&lt;P&gt;Is it acceptable ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise change the sql to -&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;                  
  create table test2(where=(ID2 is not missing)) as    
    select a.*, b.Record_ID as ID2                           
    from test a 
	left join test b
	on a.Cust_ID = b.Cust_ID and a.record_id &amp;lt; b.record_id ;              
quit;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;this will reult into 4 records:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;111 1 2
222 3 4
222 3 5
222 4 5&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 12:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-Product-within-Groups-without-Repetition/m-p/430880#M106524</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-01-25T12:56:20Z</dc:date>
    </item>
  </channel>
</rss>

