Note that the records are in the correct sorted order (e.g. $, *, %, @). The output you show is not sorted correctly. If you want the output in some nonstandard sorted order, tell me what order you want the $, *, % and @ characters in and I'll show you how to change the job.
We sort on positions 1-21 to get the records in order.
We use REMOVECC to suppress ANSI carriage control characters.
We use NODETAIL to suppress the detail records (we only want the TRAILER3 records).
We use OUTREC to get positions 1-21 followed by 4 blanks to pad the records out to the 25 bytes we need for the trailer records.
We use SECTIONS, TRAILER3 and COUNT to display positions 1-21 and the count each time the value in positions 1-21 changes.
If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from: