# Giving occurances

Can anyone pls solve in datastage.........
source column is..
A
A
B
B
B
C
C
D
........want output columns(2 cols) as.........
A 1
A 2
B 1
B 2
B 3
C 1
C 2
D 1

#### jallu

• Apr 11th, 2015

we can use stage variable in transformer stage,
u will take 2 stage variable 1 is stg1 , 2 is stg2,
u have to write if stg2=col_n then stg1+1 else ---> stg1
col_n--->stg2 , so u can get required output

#### D Hemakumar

• Apr 24th, 2015

take three stage variables in the transformer

StageVar=inputcol
StageVar1=Stagevar
StageVar2=if StageVar=StageVar1 then StageVar2+1 else 1
map the StageVar2 to the output link column

#### Aparna

• Jun 22nd, 2015

svar=> input column
svar1=> If svar=svar2 Then svar1+1 Else 1
Svar2=> svar
Next populate input column and svar1 in target

#### Mayilkannan

• Jun 17th, 2016

Sv1=Inputcolumn
Sv2=If Sv1=Sv3 then Sv4 Else 1
Sv3=Sv1
Sv4=1+Sv2

Pass Sv2 in output column

#### Pavan Kumar

• Jul 8th, 2016

Seq > Tranformer > Pivoit > Seq/Dataset
Transformer Logic:
S1,s1,s3,s4 : Stage Variables
S1= Input column
S2= 0
S3 = If inputcolumn = s1 then S2+1 else s4+1
S4=S3

#### Kumar

• Jul 8th, 2016

seq file>transformer>Seq file
1.Mode of execution in transformer must be sequential and data must be sorted on col1
2. Transformer logic:
Stv1=Input column
Stv2=if Stv1=Stv3 Then Stv2+1 Else 1
Stv3=Stv1
3.Output of transformer
Col1,Col2
Input column,Stv2

#### Amulya Kumar Panda

• Jul 11th, 2016

Job flow sequential_file-> eggregate->sort->tranformer-> sequential
fast aggregate stage use count rows and add extra column seq_no
next stage sort -key source column sort order ascending.
tranformer stage use loop while ex-@ITERATION <= DSLink13.seq_no and loop variable- "IF @ITERATION=1 THEN 1 ELSE IF @ITERATION=2 THEN 2 ELSE 3"
name S_no
output source column and loop variable name  