BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jonthiele
Fluorite | Level 6

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... 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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 ;  

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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 ;  

 

jonthiele
Fluorite | Level 6
Thanx Tom for the very(!) quick reply. This worked perfectly and is exactly what I needed.
Appreciated!!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2115 views
  • 0 likes
  • 2 in conversation