<?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: Problems with a Join (Cartesian Product?) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-a-Join-Cartesian-Product/m-p/517763#M140048</link>
    <description>&lt;P&gt;Mate, thank you so much. This looks exactly what I was looking for.&lt;/P&gt;&lt;P&gt;Deep in my heart, I hoped that you will find my post &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Since I only need to apply this code once, I don´t really have performance issues with it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&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>Sat, 01 Dec 2018 21:14:43 GMT</pubDate>
    <dc:creator>mrzlatan91</dc:creator>
    <dc:date>2018-12-01T21:14:43Z</dc:date>
    <item>
      <title>Problems with a Join (Cartesian Product?)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-a-Join-Cartesian-Product/m-p/517759#M140046</link>
      <description>&lt;P&gt;Hey guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem regarding a Join of two tables.&lt;/P&gt;&lt;P&gt;I have a table A which looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
infile datalines dlm='/';
input (Date cusip fundid value) ($);
datalines;
Jan2012/ 123 / A / 5$
Jan2012/ 123 / B / 6$
Feb2012 / 124 / A / 4$
Feb2012 / 125 / C / 4$
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And a Table b which looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
infile datalines dlm='/';
input (Date cusip relValue) ($);
datalines;
Jan2012 / 123 / 4$
Jan2012 / 124 / 5$
Jan2012 / 125 / 5$
Feb2012 / 123 / 6$
Feb2012 / 124 / 2$
Feb2012 / 125 / 4$
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I want to join these tables as followed:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile datalines dlm='/';
input (Date cusip relvalue fundid value) ($);
datalines;
Jan2012 / 123 / 4$ / A / 5$
Jan2012 / 124 / 5$ / A / . 
Jan2012 / 125 / 5$ / A / . 
Feb2012 / 123 / 6$ / A / . 
Feb2012 / 124 / 2$ / A / 4$
Feb2012 / 125 / 4$ / A / . 
Jan2012 / 123 / 4$ / B / 6$
Jan2012 / 124 / 5$ / B / .
Jan2012 / 125 / 5$ / B / .
Feb2012 / 123 / 6$ / B / .
Feb2012 / 124 / 2$ / B / .
Feb2012 / 125 / 4$ / B / .
Jan2012 / 123 / 4$ / C / .
Jan2012 / 124 / 5$ / C / .
Jan2012 / 125 / 5$ / C / .
Feb2012 / 123 / 6$ / C / .
Feb2012 / 124 / 2$ / C / .
Feb2012 / 125 / 4$ / C / 4$
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This means: For each fundid in table A, I want to add all date, cusip Observations of Table B.&lt;/P&gt;&lt;P&gt;The joined table should then show the value for this date/cusip/fundid observation if available,&lt;/P&gt;&lt;P&gt;otherwise it should show a missing value.&lt;/P&gt;&lt;P&gt;Furthermore, there is only one entry for each date, cusip observation in table b&amp;nbsp;&lt;/P&gt;&lt;P&gt;and only one entry for each date, cusip, fundid value in table b.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, Ive got the feeling that this question is stupid but Im not sure how to handle this issue.&lt;/P&gt;&lt;P&gt;Is this the Cartesian Product?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 19:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-a-Join-Cartesian-Product/m-p/517759#M140046</guid>
      <dc:creator>mrzlatan91</dc:creator>
      <dc:date>2018-12-01T19:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with a Join (Cartesian Product?)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-a-Join-Cartesian-Product/m-p/517761#M140047</link>
      <description>&lt;P&gt;Assuming i understand:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data a;
infile datalines dlm='/';
input Date :monyy7. (cusip fundid value) ($);
format date monyy7.;
datalines;
Jan2012/ 123 / A / 5$
Jan2012/ 123 / B / 6$
Feb2012 / 124 / A / 4$
Feb2012 / 125 / C / 4$
;

 

data b;
infile datalines dlm='/';
input Date : monyy7. (cusip relValue) ($);
format date monyy7.;
datalines;
Jan2012 / 123 / 4$
Jan2012 / 124 / 5$
Jan2012 / 125 / 5$
Feb2012 / 123 / 6$
Feb2012 / 124 / 2$
Feb2012 / 125 / 4$
;
proc sql;
create table want as
select x1.*,x2.value  
from
(select * from b , (select distinct fundid from a)) x1
left join a x2
on x1.fundid=x2.fundid and x1.date=x2.date and x1.cusip=x2.cusip;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Btw, If the above works, I still don't think sql is a robust approach and should switch to datastep, much much faster. But I love sql for fun atleast here&amp;nbsp; and that me being cheeky as the onus is on OP to be concerned about performance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 20:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-a-Join-Cartesian-Product/m-p/517761#M140047</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-01T20:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with a Join (Cartesian Product?)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-a-Join-Cartesian-Product/m-p/517763#M140048</link>
      <description>&lt;P&gt;Mate, thank you so much. This looks exactly what I was looking for.&lt;/P&gt;&lt;P&gt;Deep in my heart, I hoped that you will find my post &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Since I only need to apply this code once, I don´t really have performance issues with it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&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>Sat, 01 Dec 2018 21:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-a-Join-Cartesian-Product/m-p/517763#M140048</guid>
      <dc:creator>mrzlatan91</dc:creator>
      <dc:date>2018-12-01T21:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with a Join (Cartesian Product?)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-with-a-Join-Cartesian-Product/m-p/517764#M140049</link>
      <description>&lt;P&gt;The pleasure is all mine. You're most welcome!&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 21:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-with-a-Join-Cartesian-Product/m-p/517764#M140049</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-01T21:24:34Z</dc:date>
    </item>
  </channel>
</rss>

