Ranking

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
kpsita
Participant
Posts: 99
Joined: Tue Jul 21, 2009 11:43 pm

Ranking

Post by kpsita »

Hi,

I need help in implementing the ranking logic in datastage version 8.0.

In my logic, I need to rank based on three columns.

Example :- column1, column2, column3. The first set will be ranked as 1 and the second set with same value will also be ranked 1 and third set with different value will be ranked 3.

I searched the forum and tried using stage variables, but having issues when I am dealing with set of columns.

Thanks
KPSITA
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

For doing group change detection on a "set" of columns, I've found the easiest way to do that to concatenate them all into a single delimited field. So rather than check A and B and C you check the unique combination - "A|B|C". Does that make sense? The rest is proper maintenance of the rank in stage variables and knowing by how much to increment it the next time you need to increment it.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kpsita
Participant
Posts: 99
Joined: Tue Jul 21, 2009 11:43 pm

Post by kpsita »

Tahnk you for your reply.

I will concadenate and will follow as suggested. But how do I handle the rank in stage variable. I need to rank third record as '3' if first two records are same.

Thanks
KPSITA
mhester
Participant
Posts: 622
Joined: Tue Mar 04, 2003 5:26 am
Location: Phoenix, AZ
Contact:

Post by mhester »

Craig has pretty much set you on a course to handle the logic problem. Now, in my opinion, it is up to you to determine how to best handle it in DS. Think of it in terms of any programming language where you will have variables to hold results as you loop through a set of data. This is what you will do in DataStage too using stage variables.
Bicchu
Participant
Posts: 26
Joined: Sun Oct 03, 2010 10:49 pm
Location: India

Post by Bicchu »

I think using a key-break will help you to acheive your goal.
Thanks,
Pratik.
Ravi.K
Participant
Posts: 209
Joined: Sat Nov 20, 2010 11:33 pm
Location: Bangalore

Post by Ravi.K »

First Sort the data after concatenation.

Maintain three stage variables and assign default values.

svCurrent=InputrecordCol
svRank--> if svCurrent=svPrevious then svRank else svRank+1
svPrevious=InputrecordCol

Use the svRank at Transformer derivation.
Cheers
Ravi K
kpsita
Participant
Posts: 99
Joined: Tue Jul 21, 2009 11:43 pm

Post by kpsita »

In the above logic can anybody please tell why should we apply the svRank function in derivation.

The same function was applied as stage variable and I am not geting the exact result as derivation.

Thanks
KPSITA
Post Reply