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:
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;
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.
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.
This worked perfectly for my application. Thank you so much! Thank you for the quick help too.
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.
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.