Yes, it can be done, just wondering why you want to bother with it in one step, rather than two, which goes like this:
//SORTIN DD your necessary details dataset a
// DD your necessary details dataset b
//SORTOUT DD your necessary output details
//SYSIN DD *
That, along with the "usual stuff", will copy your two input datasets to one output. Put it in a PROC. Run the PROC twice with different input/output datasets.
Also note, without having headers and trailers, you can just "concatenate" wherever the data is needed, without having to have it as one dataset. Might be worth considering, especially for very large amounts of data.