That's close, but that's going to pair each consecutive record.
With SORT, it is a complex task to give to a beginner. The easier way to achieve it is in separate steps. The way to mimic the easier solution in the development of the complex solution is to do it a bit at a time, to break it into separate steps, but instead of keeping them separate, to build up each time.
KEY1 DATA1A
DATA1B
KEY2 DATA2A
DATA2B
There's a representation of the data. First thing is to arrange it like this:
KEY1 DATA1A KEY1 DATA1A
DATA1B KEY1 DATA1A
KEY2 DATA2A KEY2 DATA2A
DATA2B KEY2 DATA2A
The KEY1 group now has one record with data duplicated, and one record with all the data. On each record, the value of KEY1 is in the same place.
The file can now be SORTed on the key (with OPTION EQUALS, important).
Now we have the same data, but in the order we want. Need to turn it into the output we want.
We need "short" records. These are easy, as we have pairs of records per key, with order they were in on input retained (through OPTION EQUALS).
OUTFIL FNAMES=SHORT,BUILD=(1,50)
On SHORT, we have sorted pairs of 50-byte records now.
For the long records, we don't need the first record of each pair, as all the data is already in the second:
OUTFIL FNAMES=LONG,INCLUDE=/OMIT=(condition which gives us first record)
This is where we say "wouldn't it be handy if we had a count on each record which showed its position in the group"? That is the SEQ on the PUSH on the WHEN=GROUP, which will give either 1 or 2. Then just pick the 2s (or exclude the 1s).
Then, with the selection out of the way, just have to unscramble the order from the second record, BUILD=(51,50,1,50) and it is done.
That leaves the question of "but how do I get the data to look that way, the rest looks OK"? You know you need WHEN=GROUP, it is just that they are separate groups of two records, not intersecting groups. If there were a sequence number on the records, each record which starts the group would be an odd-numbered one.
OK, there isn't a sequence number, but we can make one. IFTHEN=(WHEN=NONE and stick a sequence number long enough for the size of the file at position 101 (after where we will put the data).
How to test the sequence number for being odd is then actually the trickiest part of the whole thing...