BookmarkSubscribeRSS Feed
pp2014
Fluorite | Level 6

I   am reading the Excel Files from the directory using the following code.  It works fine.  But I have several sheets in those execl files.

For instance for each excel file based on the products has 2 sheets, P2_abc, P3_abc, P2_xyz, P3_zyz, P2_mnk, P3_mnk and so on.

Can anybody help me how to code Proc Import part so that  I can read the sheets using macro?


%macro readin(prod);                                              

%do i=2 %to 3;

PROC IMPORT OUT= P&i_&prod datafile="&drv.\&&read1&i" dbms=excel2007  REPLACE;  sheet="P&i_&prod" ; getnames=yes;

RUN;

%end;

%mend; 


Once the Above reading the file is done then I want to set all the data together as below.

data final;

set P2_abc P3_abc P2_xyz P3_xyz ..........;

run;

I would appreciate any help in this.

Thanks

pp

1 REPLY 1
LinusH
Tourmaline | Level 20

It seems easier to use the LIBNAME Excel engine...?

Data never sleeps

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1 reply
  • 746 views
  • 0 likes
  • 2 in conversation