BookmarkSubscribeRSS Feed
Solvej
Obsidian | Level 7

Hello

 

How can in read in the following text file easily.

 

 

 

The text files are structured the following way.

afd1301033             200001011999112425000101Hjertemedicinsk klinik B, kardiologisk laboratorium 

 

I'm only interesseret in part of the lines marked by bold. I have tousands of linies. 

 

Kind regards

 

Solvej

5 REPLIES 5
novinosrin
Tourmaline | Level 20

data read;
input var1 :$15. var2 &  $100.;
var1=compress(var1,,'kd');
var2=substr(var2,anyalpha(var2));
cards;
afd1301033             200001011999112425000101Hjertemedicinsk klinik B, kardiologisk laboratorium
;
PeterClemmensen
Tourmaline | Level 20

Have you read the text file in as a SAS data set already or do you need help with that as well?

Solvej
Obsidian | Level 7
I would like help with that as well. At the moment i have used infile.
PeterClemmensen
Tourmaline | Level 20

If not, do like this and use the logic provided by @novinosrin 

 

data want;
   infile "YourPathHere\textfile.txt";
   input var1 :$15. var2 &  $100.;
run;
Tom
Super User Tom
Super User

Are you asking how to read specific columns from the line of text?
Or does the position of the strings you want vary from line to line?

Post a few lines that demonstrate the pattern. Use the Insert Code icon (looks like {i}) so that formatting is preserved.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

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
  • 5 replies
  • 1660 views
  • 4 likes
  • 4 in conversation