BookmarkSubscribeRSS Feed
vThanu
Calcite | Level 5

How do we import multiple excel files for a particula library at a time in SAS with different extensions ?

 

eg: E:\than\proc.excel

      E:\than\test.excel

      E:\than\final.excel

      E:\than\week.excel

.....     so on.

 

 

I want to read all the above file at a time into SAS..?

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

"AS with different extensions " - what does this mean.  Do you have xls, xlsx etc. files?  If so you need a different dbms for each type.  What operating system?  For unix based systems you will need PCFILES server for instance.  On Windows if you have Office installed it may be easier.

 

"I want to read all the above file at a time into SAS..?" - and how will this work, will you just be leaving it to proc import to guess what the data should look like - i.e. Garbage in garbage out?  What you get from that will likely not be exactly what you think you will get.

 

As for how to do it, get a list of files from command prompt and then call a macro e.g. (windows);

filename tmp pipe 'dir "e:/than/*.*" /b';

data _null_;
  infile tmp dlm="¬";
  input;
  if index(upcase(_infile_),"XLS") then call execute(cats('%imp_xls (fnam=',_infile_,');'));
  else call execute(cats('%imp_xlsx (fnam=',_infile_,');'));
run;
vThanu
Calcite | Level 5

In windows environment only and one specific library with differe file name with same extension...

 

using macro  I want to import (read) mutliple file into SAS at a time.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use the code provided, minor change if they are all xlsx files (remember that what you get from this maybe garbage - Excel is a bad data source, and proc import is a guessing procedure, combined they are not good):

filename tmp pipe 'dir "e:/than/*.xlsx" /b';

data _null_;
  infile tmp dlm="¬";
  input;
  call execute(cats('proc import file="e:/than/',_infile_,'" out=want',put(_n_,best.),' replace dbms=xlsx; run;'));
run;

This will create one proc import for each file in the given directory, and create an output dataset wantX where X is incremental. 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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