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!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.