BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Norman21
Lapis Lazuli | Level 10

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?

 

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
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.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User
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.

Norman21
Lapis Lazuli | Level 10

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!

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 945 views
  • 1 like
  • 2 in conversation