<?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: Join tables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75382#M21866</link>
    <description>Here is the code I used to create that output.. In your code example you have a column called 'class' that I don't see in your orginal tables.  Could that be causing your extra records?&lt;BR /&gt;
&lt;BR /&gt;
data dataset1;&lt;BR /&gt;
infile datalines delimiter = ',';&lt;BR /&gt;
	input product $ seg $ id $ loc_cd ;&lt;BR /&gt;
	datalines ;&lt;BR /&gt;
A1,SER,200,1&lt;BR /&gt;
A2,OFF,100,1&lt;BR /&gt;
A2,OFF,100,2&lt;BR /&gt;
A2,OFF,300,1&lt;BR /&gt;
A1,OFF,101,1&lt;BR /&gt;
A1,OFF,102,2&lt;BR /&gt;
A2,OFF,101,2&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data price;&lt;BR /&gt;
infile datalines delimiter = ',';&lt;BR /&gt;
	input product $ seg $ price ;&lt;BR /&gt;
	datalines ;&lt;BR /&gt;
A1,SER,20&lt;BR /&gt;
A1,OFF,30&lt;BR /&gt;
A2,SER,40&lt;BR /&gt;
A2,OFF,50&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
CREATE table Impact_1 as&lt;BR /&gt;
&lt;BR /&gt;
SELECT &lt;BR /&gt;
a.Product,&lt;BR /&gt;
a.Seg,&lt;BR /&gt;
a.ID,&lt;BR /&gt;
a.Loc_cd,&lt;BR /&gt;
b.Price&lt;BR /&gt;
FROM Dataset1 a&lt;BR /&gt;
LEFT JOIN Price b&lt;BR /&gt;
ON a.Product=b.Product&lt;BR /&gt;
AND a.Seg=b.Seg;&lt;BR /&gt;
QUIT;</description>
    <pubDate>Fri, 09 Oct 2009 21:01:33 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-10-09T21:01:33Z</dc:date>
    <item>
      <title>Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75377#M21861</link>
      <description>I have 2 data sets like these.&lt;BR /&gt;
	Data set 1		&lt;BR /&gt;
Product,	Seg,	ID,	Loc_cd,&lt;BR /&gt;
A1,	SER,	200,	1&lt;BR /&gt;
A2,	OFF,	100,	1&lt;BR /&gt;
A2,	OFF,	100,	2&lt;BR /&gt;
A2,	OFF,	300,	1&lt;BR /&gt;
A1,	OFF,	101,	1&lt;BR /&gt;
A1,	OFF,	102,	2&lt;BR /&gt;
A2,	OFF,	101,	2&lt;BR /&gt;
&lt;BR /&gt;
	Dataset Price	&lt;BR /&gt;
Product,	Seg,	Price&lt;BR /&gt;
A1,	SER,	20&lt;BR /&gt;
A1,	OFF,	30&lt;BR /&gt;
A2,	SER,	40&lt;BR /&gt;
A2,	OFF,	50&lt;BR /&gt;
What I need to do is to add another column in Dataset 1 named "Price".&lt;BR /&gt;
Which basically look Product and Sgments. When I do Left Join, It is taking cartician product including Loc_cd.The uniqueness of data in dataset 1 is Columns Product,Seg and Loc_cd.Is there any way I can solve this?&lt;BR /&gt;
Thanks</description>
      <pubDate>Fri, 09 Oct 2009 19:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75377#M21861</guid>
      <dc:creator>SP2</dc:creator>
      <dc:date>2009-10-09T19:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75378#M21862</link>
      <description>Probably.  What is the unique key for the second set?  If you showed us your code we might be able to tell you how to better handle this.</description>
      <pubDate>Fri, 09 Oct 2009 19:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75378#M21862</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-10-09T19:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75379#M21863</link>
      <description>Here is the code.&lt;BR /&gt;
CREATE  table Impact_1 as&lt;BR /&gt;
&lt;BR /&gt;
SELECT &lt;BR /&gt;
	a.Product,&lt;BR /&gt;
	a.Seg,&lt;BR /&gt;
	a.Class,&lt;BR /&gt;
	a.ID,&lt;BR /&gt;
	a.Loc_nbr,&lt;BR /&gt;
	b.Price&lt;BR /&gt;
FROM Dataset1 a&lt;BR /&gt;
	LEFT JOIN DatasetPrice b&lt;BR /&gt;
		ON a.Product=b.Product&lt;BR /&gt;
		AND a.Seg=b.Seg;&lt;BR /&gt;
QUIT	&lt;BR /&gt;
 ;&lt;BR /&gt;
The unique key in second set is Product and Seg.&lt;BR /&gt;
Basically for the same ID has multiple locations with same product and Seg.&lt;BR /&gt;
Thanks.</description>
      <pubDate>Fri, 09 Oct 2009 19:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75379#M21863</guid>
      <dc:creator>SP2</dc:creator>
      <dc:date>2009-10-09T19:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75380#M21864</link>
      <description>What do you want your final table or output to look like? Is it this?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
                            product    seg    id     loc_cd    price&lt;BR /&gt;
&lt;BR /&gt;
                                A1       OFF    101       1        30&lt;BR /&gt;
                                A1       OFF    102       2        30&lt;BR /&gt;
                                A1       SER    200       1        20&lt;BR /&gt;
                                A2       OFF    101       2        50&lt;BR /&gt;
                                A2       OFF    100       2        50&lt;BR /&gt;
                                A2       OFF    100       1        50&lt;BR /&gt;
                                A2       OFF    300       1        50&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
      <pubDate>Fri, 09 Oct 2009 20:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75380#M21864</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-09T20:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75381#M21865</link>
      <description>Yes,&lt;BR /&gt;
But instead of giving me  7 rows in the final table it is giving little over than this.&lt;BR /&gt;
In my original data there were 3058 rows for table 1,3817 for second set, but final set is giving me 3548.</description>
      <pubDate>Fri, 09 Oct 2009 20:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75381#M21865</guid>
      <dc:creator>SP2</dc:creator>
      <dc:date>2009-10-09T20:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75382#M21866</link>
      <description>Here is the code I used to create that output.. In your code example you have a column called 'class' that I don't see in your orginal tables.  Could that be causing your extra records?&lt;BR /&gt;
&lt;BR /&gt;
data dataset1;&lt;BR /&gt;
infile datalines delimiter = ',';&lt;BR /&gt;
	input product $ seg $ id $ loc_cd ;&lt;BR /&gt;
	datalines ;&lt;BR /&gt;
A1,SER,200,1&lt;BR /&gt;
A2,OFF,100,1&lt;BR /&gt;
A2,OFF,100,2&lt;BR /&gt;
A2,OFF,300,1&lt;BR /&gt;
A1,OFF,101,1&lt;BR /&gt;
A1,OFF,102,2&lt;BR /&gt;
A2,OFF,101,2&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data price;&lt;BR /&gt;
infile datalines delimiter = ',';&lt;BR /&gt;
	input product $ seg $ price ;&lt;BR /&gt;
	datalines ;&lt;BR /&gt;
A1,SER,20&lt;BR /&gt;
A1,OFF,30&lt;BR /&gt;
A2,SER,40&lt;BR /&gt;
A2,OFF,50&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
CREATE table Impact_1 as&lt;BR /&gt;
&lt;BR /&gt;
SELECT &lt;BR /&gt;
a.Product,&lt;BR /&gt;
a.Seg,&lt;BR /&gt;
a.ID,&lt;BR /&gt;
a.Loc_cd,&lt;BR /&gt;
b.Price&lt;BR /&gt;
FROM Dataset1 a&lt;BR /&gt;
LEFT JOIN Price b&lt;BR /&gt;
ON a.Product=b.Product&lt;BR /&gt;
AND a.Seg=b.Seg;&lt;BR /&gt;
QUIT;</description>
      <pubDate>Fri, 09 Oct 2009 21:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75382#M21866</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-09T21:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75383#M21867</link>
      <description>It did work.Thank you. About the Class, that is in my original table. I was simplifying the table for this forum.&lt;BR /&gt;
Thank you very much.</description>
      <pubDate>Fri, 09 Oct 2009 21:16:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/75383#M21867</guid>
      <dc:creator>SP2</dc:creator>
      <dc:date>2009-10-09T21:16:48Z</dc:date>
    </item>
  </channel>
</rss>

