<?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 SAS Merge Process [SOLVED] in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11885#M1512</link>
    <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I have a bit of a difficult problem that I thought someone else might be able to suggest some possible alternatives and post some code that might work for me.&lt;BR /&gt;
&lt;BR /&gt;
Some background, I have 2 datasets.  "A" is a list of purchases, "B" is a list of credits for purchases (ie product returns).&lt;BR /&gt;
&lt;BR /&gt;
What I would like to be able to do is remove items from dataset "A" where it has a matching record in dataset "B".&lt;BR /&gt;
&lt;BR /&gt;
Dataset A&lt;BR /&gt;
Cust    Prod    Cost&lt;BR /&gt;
ABC1  123X    $57&lt;BR /&gt;
ABC1  998C   $107&lt;BR /&gt;
ABC1  998C   $107&lt;BR /&gt;
ABC1  567D   $500&lt;BR /&gt;
&lt;BR /&gt;
Dataset B&lt;BR /&gt;
Cust    Prod    Cost&lt;BR /&gt;
ABC1  998C   $107&lt;BR /&gt;
&lt;BR /&gt;
Resulting Dataset&lt;BR /&gt;
Cust    Prod    Cost&lt;BR /&gt;
ABC1  123X    $57&lt;BR /&gt;
ABC1  998C   $107&lt;BR /&gt;
ABC1  567D   $500&lt;BR /&gt;
&lt;BR /&gt;
As you can see there are 2 records that could have been matched between "A" and "B", however only one was removed because there was only one record in "B".&lt;BR /&gt;
&lt;BR /&gt;
If anyone has some thoughts how this can be approached in SAS 9.1 that would be greatly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance&lt;BR /&gt;
DW

Changed the subject to indicate that this had been solved.&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: DWW</description>
    <pubDate>Fri, 27 Mar 2009 06:28:09 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-03-27T06:28:09Z</dc:date>
    <item>
      <title>SAS Merge Process [SOLVED]</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11885#M1512</link>
      <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I have a bit of a difficult problem that I thought someone else might be able to suggest some possible alternatives and post some code that might work for me.&lt;BR /&gt;
&lt;BR /&gt;
Some background, I have 2 datasets.  "A" is a list of purchases, "B" is a list of credits for purchases (ie product returns).&lt;BR /&gt;
&lt;BR /&gt;
What I would like to be able to do is remove items from dataset "A" where it has a matching record in dataset "B".&lt;BR /&gt;
&lt;BR /&gt;
Dataset A&lt;BR /&gt;
Cust    Prod    Cost&lt;BR /&gt;
ABC1  123X    $57&lt;BR /&gt;
ABC1  998C   $107&lt;BR /&gt;
ABC1  998C   $107&lt;BR /&gt;
ABC1  567D   $500&lt;BR /&gt;
&lt;BR /&gt;
Dataset B&lt;BR /&gt;
Cust    Prod    Cost&lt;BR /&gt;
ABC1  998C   $107&lt;BR /&gt;
&lt;BR /&gt;
Resulting Dataset&lt;BR /&gt;
Cust    Prod    Cost&lt;BR /&gt;
ABC1  123X    $57&lt;BR /&gt;
ABC1  998C   $107&lt;BR /&gt;
ABC1  567D   $500&lt;BR /&gt;
&lt;BR /&gt;
As you can see there are 2 records that could have been matched between "A" and "B", however only one was removed because there was only one record in "B".&lt;BR /&gt;
&lt;BR /&gt;
If anyone has some thoughts how this can be approached in SAS 9.1 that would be greatly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance&lt;BR /&gt;
DW

Changed the subject to indicate that this had been solved.&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: DWW</description>
      <pubDate>Fri, 27 Mar 2009 06:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11885#M1512</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-27T06:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge Process</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11886#M1513</link>
      <description>Hi DWW,&lt;BR /&gt;
&lt;BR /&gt;
try using the IN-option when merging the dataset. Both datasets have to be sorted by Cust, Prod and Cost.&lt;BR /&gt;
&lt;BR /&gt;
Example&lt;BR /&gt;
[pre]&lt;BR /&gt;
data work.c;&lt;BR /&gt;
	merge work.a &lt;BR /&gt;
                work.b(in= inB)&lt;BR /&gt;
        ;&lt;BR /&gt;
	by Cust Prod Cost;&lt;BR /&gt;
&lt;BR /&gt;
	if inB then delete;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 27 Mar 2009 07:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11886#M1513</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2009-03-27T07:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge Process</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11887#M1514</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
This code could help, but only if in the dataset B there are no repeated observations. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=a ;&lt;BR /&gt;
by cust prod cost;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=b;&lt;BR /&gt;
by cust prod cost;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data c;&lt;BR /&gt;
merge a b (in=b);&lt;BR /&gt;
by cust prod cost;&lt;BR /&gt;
if first.prod and first.cost and b then delete;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 27 Mar 2009 09:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11887#M1514</guid>
      <dc:creator>ieva</dc:creator>
      <dc:date>2009-03-27T09:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge Process</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11888#M1515</link>
      <description>Changed the code a bit: you can add one extra variable that counts how many times the same situation is repeated. So even if it is repeated also in b, this should delete only those observations that match and not all of them:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=a ;&lt;BR /&gt;
by cust prod cost;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=b;&lt;BR /&gt;
by cust prod cost;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data a1;&lt;BR /&gt;
set a;&lt;BR /&gt;
by cust prod cost;&lt;BR /&gt;
if first.cost then count=0;&lt;BR /&gt;
count+1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data b1;&lt;BR /&gt;
set b;&lt;BR /&gt;
by cust prod cost;&lt;BR /&gt;
if first.cost then count=0;&lt;BR /&gt;
count+1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data c (drop = count);&lt;BR /&gt;
merge a1 b1 (in=b);&lt;BR /&gt;
by cust prod cost count;&lt;BR /&gt;
if b then delete;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 27 Mar 2009 11:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11888#M1515</guid>
      <dc:creator>ieva</dc:creator>
      <dc:date>2009-03-27T11:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge Process</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11889#M1516</link>
      <description>The SQL set operator EXCEPT comes to mind. &lt;BR /&gt;
However, a recommendation would be based on more information like: SAS platform, data volumes and frequency of update, the use/re-use of the information, &lt;BR /&gt;
HTH&lt;BR /&gt;
PeterC</description>
      <pubDate>Fri, 27 Mar 2009 11:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11889#M1516</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-27T11:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge Process [SOLVED]</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11890#M1517</link>
      <description>Hi all, thanks for the great and fast responses.  Ieva your second solution with the counts, worked an absolute treat.  Thanks so much.&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
DW</description>
      <pubDate>Sun, 29 Mar 2009 10:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Merge-Process-SOLVED/m-p/11890#M1517</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-29T10:36:58Z</dc:date>
    </item>
  </channel>
</rss>

