Desktop productivity for business analysts and programmers

input text over varying number of lines no boundaries

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

input text over varying number of lines no boundaries

[ Edited ]

Hello, 

 

Trying to read in a .txt file that stores information in sections, broken into lines like a paragraph, but the number of lines per section is unknown. There are two blank lines between each section, I really only need the first two lines from each section. Example:

 

  1. .TXT TITLE LINE
  2. Job_Code1
  3. Job_script information
  4. Job_description_1
  5. _blank
  6. _blank
  7. Job_Code2
  8. Job_script information
  9. Job_description_1
  10. Job_description_2
  11. _blank
  12. _blank
  13. Job_Code3
  14. Job_script information
  15. Job_description_1

 

This is the code I have so far which reads by line with a line specifier, but the problem is - in this case - job_code2 spans over 4 lines while the rest spans over 3. My code is very simple and I was hoping to keep it neat, maybe using a macro to define the line specifier but I don't have much experience with macros. Any ideas? My code to read by fixed number of lines:

data want;
infile myText firstobs=2 n=5 truncover;
input Job_code $250. #2
         Job_script $250. #5;
run;


Accepted Solutions
Solution
‎10-19-2015 06:23 PM
Respected Advisor
Posts: 4,998

Re: input text over varying number of lines no boundaries

The easiest way is probably to crawl through line by line instead of defining a block of lines.  The INPUT logic might read:

 

input job_code $250.

 / job_script $250.

 / test $10.

 / test $10.;

if test > ' ' then input /;

else input;

drop test;

 

Of course if there are other variations, you will need to adjust again.  But that can be done ... you just need a good grasp of what is  in the data.

 

Good luck.

View solution in original post


All Replies
Solution
‎10-19-2015 06:23 PM
Respected Advisor
Posts: 4,998

Re: input text over varying number of lines no boundaries

The easiest way is probably to crawl through line by line instead of defining a block of lines.  The INPUT logic might read:

 

input job_code $250.

 / job_script $250.

 / test $10.

 / test $10.;

if test > ' ' then input /;

else input;

drop test;

 

Of course if there are other variations, you will need to adjust again.  But that can be done ... you just need a good grasp of what is  in the data.

 

Good luck.

Occasional Contributor
Posts: 15

Re: input text over varying number of lines no boundaries

This worked perfectly for my  application. Thank you so much! Thank you for the quick help too.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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