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 ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.