Lead Function to Perform in DataStage

82 Views Asked by At

I am looking to do LEAD() and LAG() functions to perform in DataStage.

Input C1 C2 1 100 2 200 3 300 4 400

Output - 1 C1 C2 C3 1 100 200 2 200 300 3 300 400 4 400 NULL

Output - 2 C1 C2 C3 1 100 NULL 2 200 100 3 300 200 4 400 300

Please help me getting this as I did tried with multiple ways using stage variables and loop variables but still unable to get it.

#DataStage #DataStage #LEAD #LAG

I did tried with multiple ways using stage variables and loop variables but still unable to get it.

1

There are 1 best solutions below

0
MichaelTiefenbacher On

You can make use of a transformer and its top down processing of the stage variables.

With is you can imitate a LEAD function. The LAG can be achieved by reversing the sort order which makes it a LEAD again.

The transformer processes row by row (if loops are not used) and you can access the previous row content - as stated above - by referencing a subsequent stage variable content fom a stage variable upfront.

I.e. svFirst svSecond

When svFirst is processed svSecond still has the content from the previous row. So if you have something like svFirst = svSecond you can access the data of the previous row.