BookmarkSubscribeRSS Feed
somebody
Lapis Lazuli | Level 10

I have two thousands of XLSX files. Each file has about 60 sheets. Each sheet contains some data as in the attached photo. What would be the best way to bulk import these files?

ducman1611_0-1589685884512.png

 

 

 

4 REPLIES 4
SASKiwi
PROC Star

One of the best ways I can think of is to use a LIBNAME statement using the EXCEL engine to treat an Excel workbook like a SAS library. Then you can use PROC DATASETS to copy all sheets in a workbook in one statement:

libname MyExcel EXCEL "MyExcelWorkbook.xlsx";

proc datasets library = WORK nolist;
  copy in = MyExcel out = WORK;
run;
quit;

Once you have got this working for one workbook, then you can consider automating this for say all workbooks in a directory. Eventually a SAS macro could be built to do this.

Kurt_Bremser
Super User

Do all these sheets share the same structure? Anyway, since you will not want to deal with 120000 datasets, you will need the mechanism to combine all these datasets into one or a few. Given that you import directly from Excel, this will be the challenge.

Since I also see that you have data (dates) in structure (column names), a transpose as part of the import process is also in order.

somebody
Lapis Lazuli | Level 10

yes, all the sheets are in the same format: the first two columns contains stock identity, the third is type and then other columns would be dates.

 

Kurt_Bremser
Super User

I would start out with a list of Excel file names in a data set.

Next, create a macro that

  • assigns a libname to an Excel file
  • combines all datasets (sheets) to a single WORK dataset
  • transposes this dataset to long format, BY the first three columns, deleting observations with missing values
  • names the log dataset along the name of the excel file

Run this macro repeatedly from the list of Excel file names with CALL EXECUTE.

Finally, combine the resulting long datasets into one, with a SET statement reading all long datasets.

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