<?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: Finding Duplicates using summation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492657#M129500</link>
    <description>&lt;P&gt;I understand your problem, proc transpose with logical approach might work for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test the below code and see if that works for your data&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Field1 :$8.    Field2:$8. Allowed_Amount:dollar8.;
format Allowed_Amount dollar8.;
datalines;
A1 B2 $151.00
A1 B2 -$151.00
A1 B2 $151.00
A1 B2 $220.00
A1 B2 -$151.00
A1 B2 $85.00
A1 B2 $151.00
A1 B2 $151.00
C1 D2 $84.00
C1 D2 $111.00
C1 D2 $25.00
C1 D2 -$84.00
;
run;
proc sort data=have;
by Field1 Field2  Allowed_Amount;
run;

data have;
set have;
by Field1 Field2  Allowed_Amount;
if first.Allowed_Amount then dummy=1;
else dummy+1;
Abs_Amount=ABS(Allowed_Amount);
run;

proc sort data=have;
by  Field1	Field2	abs_Amount 	dummy;
run;

proc transpose data=test out=test_trans(where=(col2 is null) drop=abs_Amount	dummy	_NAME_);
by Field1	Field2	abs_Amount 	dummy;
var Allowed_Amount;
run;
data want;
set test_trans(rename=(col1=Allowed_Amount) drop=col2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 05 Sep 2018 13:45:26 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-09-05T13:45:26Z</dc:date>
    <item>
      <title>Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/491399#M128854</link>
      <description>&lt;P&gt;I need to find duplicate rows based on 10 out of 30 fields.&amp;nbsp; I have been using proc sql and group by to accomplish this.&amp;nbsp; The only issue is that I need to also need to find these rows unique to a summed field (allowed_amount).&amp;nbsp; Here is an example of my current output, simplified to only 2 fields grouped:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Field 1&lt;/TD&gt;&lt;TD&gt;Field 2&lt;/TD&gt;&lt;TD&gt;Allowed_Amount&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;B2&lt;/TD&gt;&lt;TD&gt;-$151.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;B2&lt;/TD&gt;&lt;TD&gt;$151.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;B2&lt;/TD&gt;&lt;TD&gt;$220.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;$84.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;$111.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;$25.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;-$84.00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I am grouped by field1 and field 2,&amp;nbsp; the 3 rows with A1 and B2 are returned.&amp;nbsp; The way I need to find duplicates, rows with -151 and 151 should cancel, leaving only the row with 220.&amp;nbsp; In the final table, this should not count as a duplicate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For C1 and D2 the -84 and 84 would also cancel, but since there are unique rows with this grouping (111 and 25), I need only the 111 and 25 returned as duplicates.&amp;nbsp; I am having issues finding a way to return the 111 and 25 for C1/D2 while ignoring the rest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can solve the first issue by summing the alloweds in an intermediate table then regrouping, but this will not return the duplicates involved in the second example.&amp;nbsp; Please let me know if you need anymore clarity.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 20:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/491399#M128854</guid>
      <dc:creator>Ins_Analytic</dc:creator>
      <dc:date>2018-08-30T20:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/491416#M128860</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Field1 :$8.	Field2:$8.	Allowed_Amount:dollar8.;
format Allowed_Amount dollar8.;
datalines;
A1 B2 -$151.00
A1 B2 $151.00
A1 B2 $220.00
C1 D2 $84.00
C1 D2 $111.00
C1 D2 $25.00
C1 D2 -$84.00
;
run;

proc sql;
create table test as 
select * from have
order by 1,2,abs(Allowed_Amount);
quit;

data want(keep=Field1 Field2 Allowed_Amount);
merge test test(firstobs=2 rename=(Allowed_Amount=Allowed_Amount_) keep=Allowed_Amount);
lag_Allowed_Amount=lag(Allowed_Amount);
Lag_Field1=lag(field1);
if Lag_Field1^=field1 then call missing(lag_Allowed_Amount);
if sum(Allowed_Amount,Allowed_Amount_)=0 or sum(Allowed_Amount,lag_Allowed_Amount)=0 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Aug 2018 20:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/491416#M128860</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-08-30T20:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492342#M129361</link>
      <description>&lt;P&gt;I was previously unfamiliar with the lag function so thank you for bringing that to my attention.&amp;nbsp; I am running into one issue, though.&lt;BR /&gt;&lt;BR /&gt;Let's say that field1/field2 A1/B2 also has another row with 151.&amp;nbsp; Then there are three total rows for A1/B2 and the final data set should still include one row with 151 since the first 2 rows cancel out.&amp;nbsp; With the above given code, all rows are removed.&amp;nbsp; I cannot figure out how to adjust this properly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 15:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492342#M129361</guid>
      <dc:creator>Ins_Analytic</dc:creator>
      <dc:date>2018-09-04T15:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492346#M129363</link>
      <description>&lt;P&gt;Remove that duplicate record using PROC SORT NODUPKEY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have nodupkey;
by Field1 Field2 Allowed_Amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 15:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492346#M129363</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-09-04T15:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492352#M129367</link>
      <description>&lt;P&gt;I need the duplicate record in the final data set.&amp;nbsp; Please let me clarify.&amp;nbsp; I have added a row here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Field 1&lt;/TD&gt;&lt;TD&gt;Field 2&lt;/TD&gt;&lt;TD&gt;Allowed_Amount&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;B2&lt;/TD&gt;&lt;TD&gt;$151.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;B2&lt;/TD&gt;&lt;TD&gt;($151.00)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;B2&lt;/TD&gt;&lt;TD&gt;$151.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;B2&lt;/TD&gt;&lt;TD&gt;$220.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;$84.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;$111.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;$25.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;($84.00)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the output to have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Field 1&lt;/TD&gt;&lt;TD&gt;Field 2&lt;/TD&gt;&lt;TD&gt;Allowed_Amount&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;B2&lt;/TD&gt;&lt;TD&gt;$151.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;B2&lt;/TD&gt;&lt;TD&gt;$220.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;$111.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;$25.00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 04 Sep 2018 15:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492352#M129367</guid>
      <dc:creator>Ins_Analytic</dc:creator>
      <dc:date>2018-09-04T15:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492355#M129369</link>
      <description>&lt;P&gt;Please check your code, my previous solution works fine with that extra $150. I guess your sort order is the reason why all are canceled. If the order is $150, ($150),&amp;nbsp;&lt;SPAN&gt;$150 then my logic will cancel all 3 records. If the order is&amp;nbsp;&amp;nbsp;($150), $150,&amp;nbsp;$150 then only first 2 records will be canceled.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Field1 :$8.	Field2:$8.	Allowed_Amount:dollar8.;
format Allowed_Amount dollar8.;
datalines;
A1 B2 -$151.00
A1 B2 $151.00
A1 B2 $151.00
A1 B2 $220.00
C1 D2 $84.00
C1 D2 $111.00
C1 D2 $25.00
C1 D2 -$84.00
;
run;

proc sql;
create table test as 
select * from have
order by 1,2,abs(Allowed_Amount);
quit;

data want(keep=Field1 Field2 Allowed_Amount);
merge test test(firstobs=2 rename=(Allowed_Amount=Allowed_Amount_) keep=Allowed_Amount);
lag_Allowed_Amount=lag(Allowed_Amount);
Lag_Field1=lag(field1);
if Lag_Field1^=field1 then call missing(lag_Allowed_Amount);
if sum(Allowed_Amount,Allowed_Amount_)=0 or sum(Allowed_Amount,lag_Allowed_Amount)=0 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 16:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492355#M129369</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-09-04T16:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492394#M129393</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are correct, if the rows alternate positive, negative, positive then all are deleted, which I am trying to avoid.&amp;nbsp; This is also an issue in my original dataset, as the allowed amounts can be in any order.&amp;nbsp; I attempted to control for this by first ordering by 1,2,allowed_amount and then ordering by 1,2,abs(allowed_amount) but it appears the rows revert back to their original order?&amp;nbsp; I am unsure why this is happening:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;

create table test1 as

select * from have

order by 1,2,Allowed_Amount;

quit;

proc sql;

create table test2 as

select * from test1

order by 1,2,abs(Allowed_Amount);

quit;

 
/*
test2 Results:
Field1     Field2     Allowed_Amount

A1           B2           $151

A1           B2           $-151

A1           B2           $151

A1           B2           $220

C1           D2           $25

C1           D2           $-84

C1           D2           $84

C1           D2           $111
*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When this happens, then all rows are cancelled.&amp;nbsp; I have the same issue with my actual data set.&amp;nbsp; When the rows are manually sorted to positive, positive, negative then the code gives the desired results.&amp;nbsp; My issue is that there can be any number of rows that need to be cancelled.&amp;nbsp; So this logic works with two positives and a negative, but fails to cancel all rows with two positives and two negatives.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;

input Field1 :$8.    Field2:$8. Allowed_Amount:dollar8.;

format Allowed_Amount dollar8.;

datalines;

A1 B2 $151.00

A1 B2 -$151.00

A1 B2 $151.00

A1 B2 $220.00

A1 B2 -$151.00

C1 D2 $84.00

C1 D2 $111.00

C1 D2 $25.00

C1 D2 -$84.00

;

run;

 

proc sql;

create table test1 as

select * from have

order by 1,2,Allowed_Amount;

quit;

proc sql;

create table test2 as

select * from test1

order by 1,2,abs(Allowed_Amount);

quit;&lt;BR /&gt;
/*
test2 results:
Field1     Field2     Allowed_Amount

A1           B2           $151

A1           B2           $151

A1           B2           $-151

A1           B2           $-151

A1           B2           $220

C1           D2           $25

C1           D2           $-84

C1           D2           $84

C1           D2           $111
*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for three rows, the modified order works with your code.&amp;nbsp; With four rows, you original code that orders by abs(allowed_amount) gives me what I'm looking for.&amp;nbsp; I am having issues adjusting the code to fit all combinations of canceling rows, in my original data set.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;

input Field1 :$8.    Field2:$8. Allowed_Amount:dollar8.;

format Allowed_Amount dollar8.;

datalines;

A1 B2 $151.00

A1 B2 -$151.00

A1 B2 $151.00

A1 B2 $220.00

A1 B2 -$151.00

A1 B2 $85.00

A1 B2 $151.00

C1 D2 $84.00

C1 D2 $111.00

C1 D2 $25.00

C1 D2 -$84.00

;

run;

 

proc sql;

create table test1 as

select * from have

order by 1,2,abs(Allowed_Amount);

quit;

 

test1 results:

A1           B2           $85

A1           B2           $151

A1           B2           $-151

A1           B2           $151

A1           B2           $151

A1           B2           $-151

A1           B2           $220

C1           D2           $25

C1           D2           $-84

C1           D2           $84

C1           D2           $111

 

Want results:

A1           B2           $85

A1           B2           $220

C1           D2           $25

C1           D2           $111&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Sep 2018 17:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492394#M129393</guid>
      <dc:creator>Ins_Analytic</dc:creator>
      <dc:date>2018-09-04T17:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492397#M129395</link>
      <description>&lt;P&gt;Proper sorting of the records will resolve the issue, I would create a dummy variable to create the order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by Field1 Field2  Allowed_Amount;
run;
data have;
set have;
by Field1 Field2  Allowed_Amount;
if first.Allowed_Amount then dummy=1;
else dummy+1;
run;

proc sql;
create table test as 
select * from have
order by 1,2,abs(Allowed_Amount),dummy;
quit;

data want(keep=Field1 Field2 Allowed_Amount);
merge test test(firstobs=2 rename=(Allowed_Amount=Allowed_Amount_) keep=Allowed_Amount);
lag_Allowed_Amount=lag(Allowed_Amount);
Lag_Field1=lag(field1);
if Lag_Field1^=field1 then call missing(lag_Allowed_Amount);
if sum(Allowed_Amount,Allowed_Amount_)=0 or sum(Allowed_Amount,lag_Allowed_Amount)=0 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Sep 2018 17:56:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492397#M129395</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-09-04T17:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492483#M129418</link>
      <description>&lt;P&gt;Using the modifications to your code above, with one extra dataline to reflect a problem:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Field1 :$8.    Field2:$8. Allowed_Amount:dollar8.;
format Allowed_Amount dollar8.;

datalines;
A1 B2 $151.00
A1 B2 -$151.00
A1 B2 $151.00
A1 B2 $220.00
A1 B2 -$151.00
A1 B2 $85.00
A1 B2 $151.00
A1 B2 $151.00
C1 D2 $84.00
C1 D2 $111.00
C1 D2 $25.00
C1 D2 -$84.00
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am still missing a line with $151.&amp;nbsp; Looking at how the logic is applied, it looks like the error occurs when the logic&amp;nbsp;finds sum(allowed_amount,lag_allowed_amount)=0&amp;nbsp;on the row with allowed_amount=$151 and dummy=3 in the test table.&amp;nbsp; The row above&amp;nbsp;this with -$151 allowed_amount has already been "used" to cancel out&amp;nbsp;2 rows above.&amp;nbsp; I wanted to try and incorporate some logic with the dummy variable to help prevent this, but for some reason I cannot rename dummy=dummy_ in a similar way allowed_amount=allowed_amount_:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;

     merge test
             test(firstobs=2 rename=(Allowed_Amount=Allowed_Amount_ dummy=dummy_)
                   keep=Allowed_Amount);
     lag_Allowed_Amount=lag(Allowed_Amount);
     lag_dummy=lag(dummy);
     Lag_Field1=lag(field1);
     if Lag_Field1^=field1 then call missing(lag_Allowed_Amount);
     if lag_dummy^=dummy then call missing (lag_dummy);
     if sum(Allowed_Amount,lag_Allowed_Amount)=0 then delete;
     if dummy^=dummy_ and sum(Allowed_Amount,Allowed_Amount_)=0 then delete /*I haven't been able to experiment with this since I can't rename dummy*/;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to add logic&amp;nbsp;so that the line is only deleted a row when sum(allowed_amount,allowed_amount_)=0 when the 2 dummy variables are equal.&amp;nbsp; I think this will account for all issues.&amp;nbsp; Does this make sense, based on the problem above?&amp;nbsp; How can I rename the dummy variable?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 20:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492483#M129418</guid>
      <dc:creator>Ins_Analytic</dc:creator>
      <dc:date>2018-09-04T20:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492657#M129500</link>
      <description>&lt;P&gt;I understand your problem, proc transpose with logical approach might work for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test the below code and see if that works for your data&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Field1 :$8.    Field2:$8. Allowed_Amount:dollar8.;
format Allowed_Amount dollar8.;
datalines;
A1 B2 $151.00
A1 B2 -$151.00
A1 B2 $151.00
A1 B2 $220.00
A1 B2 -$151.00
A1 B2 $85.00
A1 B2 $151.00
A1 B2 $151.00
C1 D2 $84.00
C1 D2 $111.00
C1 D2 $25.00
C1 D2 -$84.00
;
run;
proc sort data=have;
by Field1 Field2  Allowed_Amount;
run;

data have;
set have;
by Field1 Field2  Allowed_Amount;
if first.Allowed_Amount then dummy=1;
else dummy+1;
Abs_Amount=ABS(Allowed_Amount);
run;

proc sort data=have;
by  Field1	Field2	abs_Amount 	dummy;
run;

proc transpose data=test out=test_trans(where=(col2 is null) drop=abs_Amount	dummy	_NAME_);
by Field1	Field2	abs_Amount 	dummy;
var Allowed_Amount;
run;
data want;
set test_trans(rename=(col1=Allowed_Amount) drop=col2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Sep 2018 13:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492657#M129500</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-09-05T13:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Duplicates using summation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492731#M129534</link>
      <description>&lt;P&gt;That proc transpose step is very slick.&amp;nbsp; The only issue I am having applying it to the actual data is that I have 50+ columns that the data is NOT grouped by.&amp;nbsp; The proc transpose step eliminates these columns.&amp;nbsp; I can join these columns back in, but the logic may be a bit challenging to get exactly what is needed.&amp;nbsp; I tried modifying your original solution using merge, but I added a forward/backward dummy variable, similar to what you created for allowed:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Field1 :$8.    Field2:$8. Allowed_Amount:dollar8.;
format Allowed_Amount dollar8.;
datalines;
A1 B2 $151.00
A1 B2 -$151.00
A1 B2 $151.00
A1 B2 $151.00
A1 B2 $220.00
A1 B2 -$151.00
A1 B2 $85.00
A1 B2 $151.00
C1 D2 $84.00
C1 D2 $111.00
C1 D2 $25.00
C1 D2 -$84.00
;
run;

proc sort data=have;
by Field1 Field2  Allowed_Amount;
run;

data have;
set have;
by Field1 Field2  Allowed_Amount;
if first.Allowed_Amount then dummy=1;
else dummy+1;
run;

proc sql;
create table test as
select * from have
order by 1,2,abs(Allowed_Amount),dummy;
quit;

data test_mod (rename=(Allowed_Amount=Allowed_Amount_ dummy=dummy_));
     set test; run;
data want (keep=Field1 Field2 Allowed_Amount);
     merge test (in=t)
             test_mod (firstobs=2);
     lag_Allowed_Amount=lag(Allowed_Amount);
     lag_dummy=lag(dummy);
     Lag_Field1=lag(field1);
     if t;
     if Lag_Field1^=field1 then call missing(lag_Allowed_Amount);
     if lag_dummy^=dummy then call missing (lag_dummy);
     if dummy=dummy_ and sum(Allowed_Amount,Allowed_Amount_)=0 then delete;
     if dummy=lag_dummy and sum(Allowed_Amount,lag_Allowed_Amount)=0 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This provides me with the appropriate remaining allowed amounts, but field1 and field2 have shifted down from merging with the "forward a row" table.&amp;nbsp; The last $151 row should still have A1/B2.&amp;nbsp; Do you know a fix to this issue, using this approach?&amp;nbsp; I'm worried the problem will compound and simple shift will not be enough when applied to the large data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 17:00:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Duplicates-using-summation/m-p/492731#M129534</guid>
      <dc:creator>Ins_Analytic</dc:creator>
      <dc:date>2018-09-05T17:00:24Z</dc:date>
    </item>
  </channel>
</rss>

