BookmarkSubscribeRSS Feed
OS2Rules
Obsidian | Level 7
Hi All:

I have used PROC IMPORT to input a single EXCEL spreadsheet with no problem. Someone has asked me how they can import 1,100 spreadsheets at once. They all have similar names and are all in the same directory. Is there a way to use either a wildcard (eg. 'C:\temp\file*.xls') of a FILEVAR to identify the input files? I know that I could use a macro but I'm just being lazy.

Thanks in advance.
3 REPLIES 3
deleted_user
Not applicable
Hello lazy OS2 Rules,

Here are my 2 cents, I didn't use Excel file name as the import dataset name, because some file might start with numeric or contains space or longer than what SAS required, but you can always change what you want.

Cheer.


/***************************************************;
* Program: TestImportMultipleExcel.sas
* Programmer: Clement Chen, sdclement@gmail.com
* Date: 4/4/2009
****************************************************/;

options nomlogic mprint nosymbolgen;
%let indir=C:;
%let ftype=%str(*.xls);
%let idtext=%str(*.*);

filename dir pipe "command/c find /c /i %str(%"&idtext%") &indir\&ftype";

data fname;
infile dir truncover lrecl=256;
input fname0 $ 1-256;
length fname $256;
if fname0='' then delete;
fname0=compress(upcase(fname0),'-');
_len=length(scan(fname0,-1,':'))+1;
totlen=length(fname0) - _len;
fname=substr(fname0,1,totlen);
keep fname;
run;

proc sql noprint;
select put(count(*), 3.) into: TotalN
from fname;

select distinct(fname) into: fname1- :fname%left(&TotalN)
from fname;
quit;


%macro GetExcelFile();

%do i=1 %to &TotalN;

PROC IMPORT OUT= WORK.Excel&i
DATAFILE= "&&fname&i"
DBMS=EXCEL REPLACE;
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;

%end;

%mend GetExcelFile;

%GetExcelFile(); Message was edited by: sdclement
Sudeep_Neupane
Obsidian | Level 7

Does it work with any file type?

Sudeep_Neupane
Obsidian | Level 7
I have .stc files.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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