Working with SAS 9.2 on z/OS. I have a SAS program that uses the FILE FILEVAR option to split a file based on the variable changing in the input. We output the entire record from the infile to the output files and name the output files with the variable name. We work with fixed length files and the variable I am splitting on will always be in position 1086 for 7 bytes but the length of the input file may change depending on the clients data. Because of this I have to change the record length in 3 different spots of my SAS program every time I run it. I would rather not have to change it every time so I have been trying to use the INFILE Length= to create a global variable to use with the INPUT statement, the LRECL when allocating the file names and the put statement when outputting the file. The global variable works fine for the macro to define the LRECL when allocating the file names but it does not work when defining my input or with the put statement on the output. Here is my working code without trying to use the global variable with INFILE Length=. I am trying to figure out how to make the 2230 dynamic based on the input record length. ------ begin code ----- **********************************************************************; ** FILE IN, INPUT, GET FIRST PART OF OUTPUT FILENAME **; **********************************************************************; data orig ; format fname $44.; infile filein filename = fname ; input @1086 splitvar $7. @1 orecord $char2230. ; if _n_ = 1 then do; format infnme $44. ; infnme = fname; rfile = reverse(compress(infnme)); efile = index(rfile,'.') ; lfile = length(infnme); call symput('ifile',substr(compress(infnme), 1, lfile - efile)); end ; run; **********************************************************************; ** GET ONE OF EACH SPLIT VARIABLE FOR ALLOCATING DATASETS **; **********************************************************************; proc sort data = orig NODUPKEY out=mkey ; by splitvar; run; **********************************************************************; ** MACRO THAT DELETES AND ALLOCATES THE DATASETS **; **********************************************************************; %macro allocate(flref,mfile); filename &flref "&mfile." disp=(mod,delete) ; run; filename &flref "&mfile." disp=(new,catlg,delete) space=(CYL,(250,150),RLSE) unit=sms mgmtclas=list90 recfm=fb lrecl=2230 blksize=0; run; %mend allocate; **********************************************************************; ** DATA STEP THAT CALLS THE MACRO TO ALLOCATE DATASETS **; **********************************************************************; data _null_; set mkey ; mfile = compress("&ifile"||'.W'|| splitvar); flref = compress('W' || splitvar); call execute('%allocate('||flref||','||mfile||')'); run; **********************************************************************; ** SORT DATA BEFORE FILE OUTPUT **; **********************************************************************; proc sort data = orig ; by splitvar; run; **********************************************************************; ** OUTPUT AND SPLIT THE FILES **; **********************************************************************; data _null_; set orig ; mfile = compress("&ifile"||'.W'|| splitvar); flref = compress('W' || splitvar); file flref filevar=mfile; put @1 orecord $char2230. ; run; -------- end of code ------- One way I have been able to get the INPUT to work was write out the data step to TEMP and then use INCLUDE to bring that file back in to define my input but this just seems kind of hokey and too much coding. I would think there has to be a simpler way then doing this. This basically makes me create 3 DATA steps. One data step to get the INFILE LENGTH. A 2nd data step to Create the temp file and the resulting temp file is the 3rd data step included back into the program. --------- begin test code ---------------- data _null; format inlen 4. ; format fname $44.; infile filein filename = fname length = inlen obs=1 ; input ; format reclen 4. ; format infnme $44. ; reclen = inlen ; infnme = fname; rfile = reverse(compress(infnme)); efile = index(rfile,'.') ; lfile = length(infnme); call symput('ifile',substr(compress(infnme), 1, lfile - efile)); call symput('clen',trim(left(reclen))); run; filename pgm temp; data _null_; clen = &clen.; record = compress('¬¬¬¬¬¬@001¬¬¬orecord¬$char' || clen || '.'); record =translate(record,' ','¬'); file pgm; put 'data orig;'; put 'infile filein;'; put 'input'; put '@1086 splitvar $7.'; put record; put ';'; put 'run;'; run; %include pgm; --------------- end of test code -----------------------
... View more