/*** TIP 00383 ***/
I need to sort an input file on 2 fields. The input file is fixed
length 25000 byte.  The problem I have is some of the records span 
multiple lines, say multiple records.  I need to keep those groups 
together when doing the sort.  Here's a sample input file,

0001AAA1111ASADFJA;DFJ          -line1
0001CCC1122DAF'SDFK'SDKF        -line2
ADSAF'DKF'A;SDKF'AD;KFD         -line3
0001BBB2222ADFASDFLJAD'KF       -line4
DADFA'DSFKA'SDKF'DKFDFD         -line5
ADFAKFD';LKDSF'AKSDFSDF         -line6
0001DDD1111DADAFSAFDFF          -line7

Sort parameters are: 3 positions from 5th byte
        and          4 positions from 8th byte

A new record is identified by '0001' at the start of the record. If it
is not '0001', that means, the record is a continuation of the
previous line and this record needs to be grouped together.

So the sample output will be:

0001AAA1111ASADFJA;DFJ          -line1
0001BBB2222ADFASDFLJAD'KF       -line4
DADFA'DSFKA'SDKF'DKFDFD         -line5
ADFAKFD';LKDSF'AKSDFSDF         -line6
0001CCC1122DAF'SDFK'SDKF        -line2
ADSAF'DKF'A;SDKF'AD;KFD         -line3
0001DDD1111DADAFSAFDFF          -line7

Any suggestion how I can accomplish this using SAS?

Solution #1 By Charles Patridge filename rawdata "c:\download\rawdata.txt"; data test; length record $80 sort $ 7.; retain group sort; infile rawdata missover; input @1 code $4. @; if code = '0001' then do; seq = 0; group + 1; input @1 record ; sort = substr(record,5,3)|| substr(record,8,4); end; if code ne '0001' then input @1 record ; seq + 1; run; proc sort data=test out=testsort; by sort group seq; run; /*** rawdata.txt looks like this 0001AAA1111ASADFJA;DFJ -line1 0001CCC1122DAF'SDFK'SDKF -line2 ADSAF'DKF'A;SDKF'AD;KFD -line3 0001BBB2222ADFASDFLJAD'KF -line4 DADFA'DSFKA'SDKF'DKFDFD -line5 ADFAKFD';LKDSF'AKSDFSDF -line6 0001DDD1111DADAFSAFDFF -line7 ***/ /*** end of tip 00383 ***/