BookmarkSubscribeRSS Feed
TarunKumar
Pyrite | Level 9


Hi,

I have multiple excel sheet. i want to import all sheets with the help Of macro.

3 REPLIES 3
allurai0412
Fluorite | Level 6

hi ,

libname engine will also helps you ...for importing ....

but try this .....i have excel (Y3DTR.XLS) having two sheets named PURCHASE , SWITCHES


%MACRO IMPR(IMP,OUT_DAT,EXL_SHT);

PROC IMPORT DATAFILE="&IMP" DBMS=EXCEL OUT=&OUT_DAT REPLACE; /*for oupput dataset for each SHEET */

SHEET="&EXL_SHT";    /*for specifying sheets  */

MIXED=YES;

RUN;

%MEND IMPR;

%IMPR(C:\Users\galax_allu\Desktop\Y3DTR.XLS,PURCHASE, PUR);

%IMPR(C:\Users\galax_allu\Desktop\Y3DTR.XLS,SWITCHES, SWT);

Regards,

Allu

TarunKumar
Pyrite | Level 9

Thanx for valuable support.

SASKiwi
PROC Star

Here's slightly more automated version where the workbook tab names are used for the SAS dataset names. This means the tabs should be named using SAS naming conventions (A-Z, 0-9, underscores only and no blanks):

%macro Import_Excel_Workbook ( Excel_Libname = INXLSX

                              ,Excel_File =

                              ,SAS_Libname = WORK

                             );

%if &Excel_File ne %then %do;

  libname &excel_libname excel "&Excel_File"

%end;

%if (%sysfunc(libref(&excel_libname))) %then

  %put %sysfunc(sysmsg());

%else %do;

%let tmp_sheetlist1 = ;

proc sql noprint ;

select  nliteral(memname)

       ,memname

into  :tmp_sheetlist1 separated by ' '

     ,:dummy

from dictionary.members

where libname = "%upcase(&excel_libname.)" and memname not contains '#'

order by memname

;

quit ;

proc datasets library = &SAS_libname nolist;

  copy in = &excel_libname out = &SAS_libname;

  select &tmp_sheetlist1;

  run;

quit;

  %if &Excel_File ne %then %do;

libname &excel_libname clear; 

  %end;

%end;

%mend Import_Excel_Workbook;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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