BookmarkSubscribeRSS Feed
nayab_shaik
Calcite | Level 5

Hi Team,

i have different name of excel files how to import all excel files at a time by using macros

5 REPLIES 5
VinitvictorCorr
Quartz | Level 8
it depends on what are the names of these excel files.
Kurt_Bremser
Super User

As you have already been told multiple times, use descriptive subject lines!

 

Start with successfully importing one Excel file. Then look what needs to be made dynamic, and replace that with macro variables. Finally, look for a way to create those macro variables automatically, by determining from how your files are stored (single vs. multiple directories etc.).

Shmuel
Garnet | Level 18

Clarify:

1) Are all excel files in the same folder or in different folders?
    Are their names all in same format? (differ by suffix? date? something else?)

2) Are all excel files of same type: .xls or .xlsx and which of them ?

3) Are all excel files with same columns format? 
    Do you wand to import all into one SAS dataset or each in its own one?
    

All those info affect how to code the macro.

s_lassen
Meteorite | Level 14

For a thing like that, I would not use macros. I think it is easier and safer to write a program to a temporary file, and then %INCLUDE that, e.g.:

filename dirlist pipe 'dir c:\myfiles\*.xlsx /b';

filename tempsas temp;
data _null_;
  infile dirlist;
  input;
  filename=_infile_;
  put "Proc import FILE='c:\myfiles\" filename +(-1) "'"/
        '  DBMS=EXCEL5 REPLACE out=Excel_Imp' _N_ ';' /
        '  GETNAMES=yes;' /
        'RUN;'
        ;
run;

%include tempsas;

Before submitting the %include statement, you can open the TEMPSAS file in an editor window, see if the generated code looks right, and try submitting one of the generated PROC IMPORT statements, to test if it works.

Kurt_Bremser
Super User

BTW, a google search for "sas communities reading multiple excel files" will reveal the many, many times this subject has been covered before.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 480 views
  • 0 likes
  • 5 in conversation