DATA Step, Macro, Functions and more

Importing many txt files with differant layouts all in once

Reply
Contributor
Posts: 20

Importing many txt files with differant layouts all in once

[ Edited ]

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

Super User
Posts: 19,772

Re: Importing many txt files with differant layouts all in once

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...

Respected Advisor
Posts: 4,920

Re: Importing many txt files with differant layouts all in once

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

PG
Contributor
Posts: 20

Re: Importing many txt files with differant layouts all in once

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

Super User
Posts: 19,772

Re: Importing many txt files with differant layouts all in once

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.

Contributor
Posts: 20

Re: Importing many txt files with differant layouts all in once

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

Super User
Posts: 19,772

Re: Importing many txt files with differant layouts all in once

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

Super User
Posts: 19,772

Re: Importing many txt files with differant layouts all in once

 

 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;

 

Ask a Question
Discussion stats
  • 7 replies
  • 291 views
  • 0 likes
  • 3 in conversation