Page 1 of 1

Sort the output again using sort.

Posted: Tue Sep 13, 2016 2:45 pm
by Maven JJ
I have a file having state code and some more records in it. I need to find that how many records are there for each state code.The 150-151 colums hold the US state code.

Records in dataset are like this:

Code: Select all

|ST|AGENT:CODE|EFF DATE| 
========================
IL |A |021    |20160128| 
MI |A |002    |20160110| 
CT |A |036    |20160208| 
CT |A |266    |20160117| 
AK |A |723    |20160107| 
MD |A |876    |20160114| 
CA |A |244    |20160102| 
MA |A |499    |20160225| 

So far i have written a sort like this:

Code: Select all

//SYSIN DD * 
INREC FIELDS=(1,224,225:C'000001') 
SORT FIELDS=(150,2,CH,A) 
INCLUDE COND=(150,2,CH,NE,C' ',AND,150,2,CH,NE,C'==') 
SUM FIELDS=(225,6),FORMAT=ZD 
OUTREC FIELDS=(1:150,2,3:C' - ',6:225,6) 
It gives me output

Code: Select all

AK - 000032 
AL - 000321 
AR - 000013 
AZ - 000032 
CA - 000234 
CO - 000128 
The problem is that the output records are sorted in the alphabetical order of the state code, while I wanted to output in the ascending order of the number of occurence (second column in output) , how do I do that?

Can anyone help me out with this please? I think it can be done in a single step instead of writing another step to sort the output again.

Re: Sort the output again using sort.

Posted: Wed Sep 14, 2016 3:36 am
by Magesh_j
Can be done without sorting twice, but cant be done in single pass.

To find a count of a state, if it is already in sorted order by state, then you need not require a sort or sumfield

untested code

Code: Select all

OPTION COPY
OUTFIL SECTIONS=(150,2,TRAILER3=(150,2,C' - ',COUNT=(EDIT=(TTTTTT)))),REMOVECC,NODETAIL
And 2nd step

Code: Select all

SORT FIELDS=(6,6,ZD,A)
Regards,
Magesh