Depending on the number of occurrences you have for each key you can modify this JCL to meet your requirements Mainframe Sort JCL - transpose the rows to column