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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1476 views
  • 0 likes
  • 3 in conversation