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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

2 REPLIES 2
Astounding
PROC Star

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.

mhouse
Fluorite | Level 6

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 822 views
  • 0 likes
  • 2 in conversation