I have a similar situation, where I need to break up a file with over 5.5 million records into smaller files for processing through a module on a z\OS mainframe. Lengths of records are highly variable, but there's an identifying number at the beginning of each, and the final digit of that ID is at byte 13 of the file. This file actually contains a sample of a larger dataset, and since it's large enough, I know that the number of records for each terminal digit will be approximately the same, around 560,000-590,000 records. So a simple split criterion in this case is one file for each terminal digit.

I've taken a macro approach, using SAS CONNECT, which means I need to dynamically allocate the filenames before writing to them. Here, an active SAS CONNECT session is already established.

The macro definition must be inside an rsubmit block, as it will be called in the server session. Note also that the count variable in the loop is set to begin at 0 rather than 1. This is so that each value of count corresponds to one of the unique ID's terminal digits (0-9).

rsubmit;

************* EDIT THESE VARIABLES *************;
* input source filename;
%let myinfile='source.file.on.main.frame';

* base name of the files to allocate, with no numeric suffix;
%let filestem=username.src.slice;

* number of slice files to allocate, minus 1;
%let slicenum=9;
************** END OF VARIABLES TO EDIT **************;

filename src &myinfile;

%macro slicefile;
%do count=0 %to &slicenum;

%*allocate file;
filename slice&&count "&filestem&&count" disp=(new,catlg) label=(,,,,expdt=99365)
space=(15643,(10000,2000),rlse) recfm=vb lrecl=15643 noprompt;

%*write data for one terminal digit to the file;
data _null_;
infile src;
file slice&&count;
input @13 trm 1.;
if trm = &count;
put _infile_;
run;

%*clear filename to release lock on the file;
filename slice&&count;
%end; %* do loop;

%mend slicefile;
%slicefile

endrsubmit;

I'm less than happy that this must read the entire input file ten times, but I haven't yet had time to work out how to get it to write to a different file based on the terminal ID digit on a line by line basis during a single read of the input file.