To my great surprise or maybe incompetence, I couldn't find an article or usage note detailing how to find the maximum length of the records in a file. So I wrote a snippet and thought I could share it here.
Here's one way to achieve this:
%* Create a file with 4 records; data _null_; file "&wdir/t.txt" lrecl=%sysevalf(2**30-1); length A $32767; A=repeat('a',32766); put 'aa' / A A A / A / 'aaa'; run; %* Find the record lengths in that file; data _null_; infile "&wdir/t.txt" lrecl=%sysevalf(2**30-1) end=LASTREC length=LS; input ; retain RECMINLEN RECMAXLEN RECNB; RECNB+1; RECMINLEN = min(RECMINLEN, LS); RECMAXLEN = max(RECMAXLEN, LS); if LASTREC then do; call symputx('recmaxlen', RECMAXLEN); call symputx('recminlen', RECMINLEN); call symputx('recnb ', RECNB ); end; run; %* Print the record information; %put &=recmaxlen &=recminlen &=recnb;
This prints out:
RECMAXLEN=98303 RECMINLEN=2 RECNB=4
Note that if the record length exceeds 1,073,741,824 (2^30) bytes, which is the maximum that SAS can handle, this method fails.
I'm looking forward to reading about ways to improve on the logic detailed.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.