Page 1 of 1

Extract First Row From Each Group of Rows

PostPosted: Wed Sep 04, 2013 7:45 pm
by wallacec
Hi,

I have an input file with the following fields:

1) FLD1   X(2)
2) FLD2   X(1)
3) FLD3   X(3)
4) FLD4   X(4)

INPUT:
----|----|----|
11AXXX9999                  <- (1)
11AYYY9999                  <- (2)
13AZZZ9999                  <- (3)
21BXXX9999                  <- (4)
22BXXX9999                  <- (5)


I need to split all rows in the file into 2 separate files using the following rules:
1) Group all rows by FLD2 and sort by FLD1 AND FLD3 in ascending order
2) Put first row in each group into one file and put remaining rows in each group into another file
3) Combine FLD1 and FLD3 into a new field and place at the beginning of each row

Below is the expected output. Could anyone advise how this can be accomplished using SORT?

OUTPUT 1:
----|----|----|
11XXX11AXXX9999             <- (1)
21XXX21BXXX9999             <- (4)

OUTPUT 2:
----|----|----|
11YYY11AYYY9999             <- (2)
13ZZZ13AZZZ9999             <- (3)
22XXX22BXXX9999             <- (5)


Thanks.

Re: Extract First Row From Each Group of Rows

PostPosted: Thu Sep 05, 2013 5:23 am
by BillyBoyo
If you sort on FLD2, then 1 then 3, then in OUTREC use IFTHEN=(WHEN=GROUP on FLD2 and PUSH a sequence number (to the end of the record if fixed-length, start of the record if variable).

In OUTFIL, have one file which has INCLUDE= for the sequence number being one, and a second file with SAVE (which will get all the other records on that file). Use BUILD on each of the OUTFIL datasets to do your final arrangement of the data.

Re: Extract First Row From Each Group of Rows

PostPosted: Thu Sep 05, 2013 5:08 pm
by wallacec
Since I am not familiar with the control statements you mentioned, I will do a search to verify. Thanks for the suggestion.

Re: Extract First Row From Each Group of Rows

PostPosted: Thu Sep 05, 2013 6:29 pm
by BillyBoyo
Good for you. If you get stuck with any of it, someone will be here.