BookmarkSubscribeRSS Feed
japfvg
Fluorite | Level 6

Dear experts:  

 

I have this issue, I have a text file with info like the following (unstructured data):

 

 

Report Title
Report Subtitle
Dates, etc, etc
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
-------------------------------------------------------
A0100 Info about something
      important that is needed
      to capture
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
..................................................................

 

 

The information I'm looking for is located after the "A0100" and continues for the next 2 lines ("Info about something important that is needed to capture"), sometimes it's 6 lines or 8 (it may vary) but the message always starts with the "A0100" and also starts at position 7 and ends at 31 and is needed in one field called "message" in one record.

 

If there is another message below, it will be in another record (same field).

 

Any ideas on how to get this?

 

Thanks in advance.

 

Kind regards!

 

FerV

1 REPLY 1
Tom
Super User Tom
Super User

Read ahead.

 

As long as you can tell by looking at some part of the next line (or current line) that it is an continuation.

 

In your case is looks like the continuation lines have blanks in the first field so perhaps something like this.

data want;
  infile 'myfile.txt' truncover end=eof;
  length id $5 rec 8 fullstring $300 ;
  input id $5 fullstring $100. ;
  do rec=1 by 1 until (eof or _infile_^=: '     ');
    if not eof then do;
      input @@ ;
      if _infile_ ^=: '     ' then do;
        input @6 nextstring $100.;
        fullstring=catx(' ',fullstring,nextstring);
      end;
    end;
  end;
  drop nextstring;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 684 views
  • 1 like
  • 2 in conversation