When reading a text file using the INFILE statement, the documentation tells me that the delimiter between variables is a space. However, I want to read an entire line of text that contains spaces - as a single variable. I believe to override the space delimiter, I need to use the delimiter= option on the INFILE statement. However, I can't seem to find the right character(s) to override the default. I've used DLM='' and DLM='0x0D'x and DLM=CRLF all without the result I need.
My current program looks like this:
DATA TEMPFILE ;
ATTRIB TEMPLINE LENGTH = $200 ;
INFILE "C:\TEMP.TXT" DELIMITER = '0x0D'x ; /* or DELIMITER = '' */
INPUT TEMPLINE ;
RUN ;
where TEMP.TXT is:
FIRSTWORD SECONDWORD MOREWORDS
THISISAVERYLONG WORD
TEST!TEST@TEST# test
The program only grabs the data before the first space. I can't seem to override this. I know I'm simply missing some option but I can't seem to find it reading the documentation or googling for examples. Thanx in advance...
You don't need to mess with the delimiter to read a full line.
Just use formatted input. Use the TRUNCOVER infile option to handle short lines. Use the $CHAR informat to preserve any leading spaces on the line.
Or just use the _INFILE_ automatic variable.
DATA TEMPFILE ;
ATTRIB TEMPLINE LENGTH = $200 ;
INFILE "C:\TEMP.TXT" TRUNCOVER;
INPUT TEMPLINE $char200.;
RUN ;
DATA TEMPFILE ;
ATTRIB TEMPLINE LENGTH = $200 ;
INFILE "C:\TEMP.TXT" ;
INPUT ;
TEMPLINE= _infile_;
RUN ;
You don't need to mess with the delimiter to read a full line.
Just use formatted input. Use the TRUNCOVER infile option to handle short lines. Use the $CHAR informat to preserve any leading spaces on the line.
Or just use the _INFILE_ automatic variable.
DATA TEMPFILE ;
ATTRIB TEMPLINE LENGTH = $200 ;
INFILE "C:\TEMP.TXT" TRUNCOVER;
INPUT TEMPLINE $char200.;
RUN ;
DATA TEMPFILE ;
ATTRIB TEMPLINE LENGTH = $200 ;
INFILE "C:\TEMP.TXT" ;
INPUT ;
TEMPLINE= _infile_;
RUN ;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.