Hi,
I have a text file with a repeating structure, and am having difficulty importing it using either infile or proc import. Each line ends with a CR LF.
This is what I have:
first line (to be skipped)
<blank>
1
10:02:03
some text, that might contain commas or semicolons
<blank>
2
10:02:04
some more text
<blank>
3
10:02:07
yet more text
etc.
This is what I want:
Var1 Var2 Var3
1 10:02:03 some text, that might contain commas or semicolons
2 10:02:04 some more text
3 10:02:07 yet more text
etc.
This should be simple but it has me stumped! Can anyone help?
data want;
infile "yourfile" termstr=CRLF truncover;
input; /* skips blank line */
input var1; /* numeric */
input var2 time8.; /* time */
format var2 time8.;
input var3 $100.; /* text, adapt length to maximum expected */
run;
This will work as long as the 4-line sequence is reliably kept; if the sequence might change, further measures are necessary.
data want;
infile "yourfile" termstr=CRLF truncover;
input; /* skips blank line */
input var1; /* numeric */
input var2 time8.; /* time */
format var2 time8.;
input var3 $100.; /* text, adapt length to maximum expected */
run;
This will work as long as the 4-line sequence is reliably kept; if the sequence might change, further measures are necessary.
Multiple INPUT statements! That never occurred to me.
KurtBremser, your solution worked after one minor modification (adding firstobs=2 to the infile statement).
Thanks a million!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.