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;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1082 views
  • 0 likes
  • 3 in conversation