I have had lots of 'fun' doing this! Try the code below, it works for me, I took out some of the error handly to get an easy cut/paste. Also, it can be sensitive to the RACF/ACF2 authority of who is invoking the REXX and whether the SORT program in on the APF listing. Try looking in your syslog at the time the script fails for odd messages.
"ALLOC SYSPRINT SYSOUT CLASS(X)"
if RC ¬= 0 then do
signal Exit_Here
End
"ALLOC F(sysin) DA('"parmlib"') reuse"
if RC ¬= 0 then do
signal Exit_Here
End
"ALLOC F(sortin) DA('"dsn2"') reuse"
if RC ¬= 0 then do
signal Exit_Here
End
"ALLOC F(sortout) DA('"dsn2"') reuse"
if RC ¬= 0 then do
signal Exit_Here
End
"CALL 'SYS1.SICELINK(SORT)'"
"FREE F(sysin,sortin,sortout,sysprint)"
SORT is a psudonim for DFOSRT where I work.