<?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: Combine data from 2 files which has duplicate keys in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-data-from-2-files-which-has-duplicate-keys/m-p/943471#M369777</link>
    <description>&lt;P&gt;You could use a DATA step merge or an SQL join. The join is simpler to code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, crate the input data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data h1;
	infile datalines dsd dlm=' ';
	input id  key;
datalines;
1234 5678
3456 5678
;

data h2;
	infile datalines dsd dlm=' ';
	input key data:$10.;
datalines;
5678 abc.com
5678 ghi.com
5678 xyz.com
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then do the join:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql number;
select h2.*, Id
	from h1
	  inner join
         h2
	on h1.key=h2.key
	order by id, data
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 Sep 2024 12:46:14 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2024-09-11T12:46:14Z</dc:date>
    <item>
      <title>Combine data from 2 files which has duplicate keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-data-from-2-files-which-has-duplicate-keys/m-p/943461#M369773</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 files on mainframe and both files have duplicate keys.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;first file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" class="xl63" style="height: 14.4pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;KEY&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt; border-top: none;"&gt;1234&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5678&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.4pt; border-top: none;"&gt;3456&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5678&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;second file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" class="xl65" style="height: 14.4pt; width: 48pt;"&gt;KEY&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;DATA&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;5678&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;abc.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;5678&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;ghi.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;5678&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;xyz.com&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;first and second files have duplicate keys. I need to repeat 3 records from 2nd file for each record in first file. My final output should be like this:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="3" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" class="xl65" style="height: 14.4pt; width: 48pt;"&gt;KEY&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;DATA&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;5678&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;abc.com&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1234&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;5678&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;ghi.com&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1234&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;5678&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;xyz.com&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1234&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;5678&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;abc.com&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3456&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;5678&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;ghi.com&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3456&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;5678&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;xyz.com&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3456&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I achieve this in SAS mainframe.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help in advance!!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2024 12:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-data-from-2-files-which-has-duplicate-keys/m-p/943461#M369773</guid>
      <dc:creator>gandikk</dc:creator>
      <dc:date>2024-09-11T12:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Combine data from 2 files which has duplicate keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-data-from-2-files-which-has-duplicate-keys/m-p/943471#M369777</link>
      <description>&lt;P&gt;You could use a DATA step merge or an SQL join. The join is simpler to code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, crate the input data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data h1;
	infile datalines dsd dlm=' ';
	input id  key;
datalines;
1234 5678
3456 5678
;

data h2;
	infile datalines dsd dlm=' ';
	input key data:$10.;
datalines;
5678 abc.com
5678 ghi.com
5678 xyz.com
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then do the join:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql number;
select h2.*, Id
	from h1
	  inner join
         h2
	on h1.key=h2.key
	order by id, data
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2024 12:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-data-from-2-files-which-has-duplicate-keys/m-p/943471#M369777</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-09-11T12:46:14Z</dc:date>
    </item>
  </channel>
</rss>

