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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.