BookmarkSubscribeRSS Feed
srdhoble
Calcite | Level 5

Hi Team,

               My requirement is to import many .txt files each with differant layout all at once.And to save them as sas datasets in work library.Can someone please help me on this.Thanks!

 

NOTE:I cannot make copy of files and store them in one temp location.File sizes are huge

7 REPLIES 7
Reeza
Super User

You can write a macro.

 

How do you know where the files are? Do you have a list, all in a folder?

 

http://www.sas.com/content/dam/SAS/en_ca/User%20Group%20Presentations/Victoria-User-Group/Macros-for...

PGStats
Opal | Level 21

Where/How is the layout of your text files described?

PG
srdhoble
Calcite | Level 5

These are pipe delimited .txt files. and all of them are distributed over 4 folder locations.

Reeza
Super User

1. Can proc import work or will you need a customized data step for each file?

 

If proc import works you can try and automate it.

srdhoble
Calcite | Level 5

Automating Proc import would be fine with me...any idea how to go about it?

Reeza
Super User

The first link I provided is a step by step instruction on how to do exactly that.

Reeza
Super User

 

 You can use a script to determine all the files in the folder (Assuming Windows);

http://support.sas.com/kb/45/805.html

 

Once those are in a dataset you can call the import macro using call execute.

 

%macro import_text_file(path, out);
proc import data=&out datafile="&path" dbms=dlm;
delimiter='|'; getnames=yes;
run;

%mend;

 

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
  • 7 replies
  • 2029 views
  • 0 likes
  • 3 in conversation