Counting the largest number of multi-values in X no. of cols

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Does it have to be 20 columns, or can you get them as one column? If not, assemble a field-mark delimited dynamic array containing the 20 columns. Apply the Counts() function to return an equivalent dynamic array of the number of value marks in each field (you may need to convert to a non-delimiter character for this). Apply the Maximum() function to get the highest count. Use Locate to find the first occurrence of this in the counts dynamic array. Create a business rule about how to handle more than one field having the same maximum count.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Does it have to be 20 columns, or can you get them as one column? If not, assemble a field-mark delimited dynamic array containing the 20 columns. Apply the Counts() function to return an equivalent dynamic array of the number of value marks in each field (you may need to convert to a non-delimiter character for this). Apply the Maximum() function to get the highest count. Use Locate to find the first occurrence of this in the counts dynamic array. Create a business rule about how to handle more than one field having the same maximum count.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rachit82
Premium Member
Premium Member
Posts: 41
Joined: Thu Jul 17, 2008 9:49 am

Post by rachit82 »

ray.wurlod wrote:Does it have to be 20 columns, or can you get them as one column? If not, assemble a field-mark delimited dynamic array containing the 20 columns. Apply the Counts() function to return an equivalent dynamic array of the number of value marks in each field (you may need to convert to a non-delimiter character for this). Apply the Maximum() function to get the highest count. Use Locate to find the first occurrence of this in the counts dynamic array. Create a business rule about how to handle more than one field having the same maximum count.
What i meant was a variable number of columns....

so you mean to say Count(col1:col2:col3:...:20,@FM)

or is it better to get maximum(col1:col2:col3....col20)?

Thanks
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If you want the maximum count, no.

Figure out your actual requirement and deploy the appropriate functions.
I've suggested the most likely.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rachit82
Premium Member
Premium Member
Posts: 41
Joined: Thu Jul 17, 2008 9:49 am

Post by rachit82 »

ray.wurlod wrote:If you want the maximum count, no.

Figure out your actual requirement and deploy the appropriate functions.
I've suggested the most likely.
The following is the result that i deployed as a server routine:

Function TestCompare<Arg1>

MaxCount = 0
PosOfMax = 0
NArgs = dcount<Arg1,"|">
For i = to Nargs
ThisArg = Field(Arg1,"|",i)
ThisCount = DCOUNT(ThisArg, @VM)
if ThisCount > MaxCount then
MaxCount = ThisCount
PosOfMax = i
End
Next i
Ans = Field(Arg1,"|",PosOfMax)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You've just reinvented the MAXIMUM() function.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rachit82
Premium Member
Premium Member
Posts: 41
Joined: Thu Jul 17, 2008 9:49 am

Post by rachit82 »

ray.wurlod wrote:You've just reinvented the MAXIMUM() function.
I needed the dynamic array as result which is the largest among all the columns that i am comparing.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Yes, that's what the Maximum() function does.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply