Page 1 of 1

Adding the counts of duplicates while keeping the duplicate.

Posted: Tue May 16, 2017 1:31 pm
by Atul Bhosale
Hi,

I'm struggling with a situation where I want to find records in a file that have duplicate values in one part of the record. I can do this, but I also want to retain all records in the output.

Here is the example:

Input:

Code: Select all

ABCDEF 
ABCDEF 
ABCDEF
ABCDEF
FGHIJK 
FGHIJK 
FGHIJK 
FGHIJK 
outfile:

Code: Select all

ABCDEF 4 
ABCDEF 4
ABCDEF 4 
FGHIJK 4 
FGHIJK 4 
FGHIJK 4 
FGHIJK 4 
I've used this:

Code: Select all

INREC FIELDS=(1,6,9:2X,SEQNUM,8,ZD) 
SORT FIELDS=(1,6,CH,A) 
SUM FIELDS=(11,8,ZD) 
But it's not working as per expectation and am getting this as output:

Code: Select all

ABCDEF 4 
FGHIJK 4 
I actually want to keep the duplicate records, while the above one removes them. How can I do that, please advise me on this.

Thanks

Re: Adding the counts of duplicates while keeping the duplicate.

Posted: Tue May 16, 2017 10:13 pm
by zprogrammer
Have your output of SUM FIELDS and do a JOIN KEYS, Also another option ICETOOL

Re: Adding the counts of duplicates while keeping the duplicate.

Posted: Thu May 18, 2017 1:51 pm
by Atul Bhosale
zprogrammer wrote: Have your output of SUM FIELDS and do a JOIN KEYS, Also another option ICETOOL
Have your output of SUM FIELDS, means what do I do?

Re: Adding the counts of duplicates while keeping the duplicate.

Posted: Thu Jun 01, 2017 1:50 pm
by Chandan Yadav
Atul Bhosale wrote: Have your output of SUM FIELDS, means what do I do?
What Z programmer mean to say is execute two steps
1. Do the sum fields and get the output as you have mentioned
2. Use join keys to join your input file and o/p from step1, get the desired result

Thanks,
Chandan