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

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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.

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