BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
finans_sas
Quartz | Level 8

Hi Everyone,

I am trying to read a few hundred excel files (.xlsx) into SAS. Below is the code that I have put together from various sources (mostly UCLA). Each excel file has the same column names, but the length of the strings in the columns change from one excel file to another. The challenge is that each excel file has two sheets, and data is located in "Data Sheet". I have been trying to figure out where to put a statement like "sheet="Data Sheet" in the code, but I could not figure out where. (Note: I also have a macro code that imports all this data using PROC IMPORT, but truncation is such a big problem that I am now using the code below). I look forward to hearing your suggestions.

Thanks!

%let dirname = _____________;

      filename DIRLIST pipe "dir /B &dirname\*.xlsx";

     

      data dirlist ;

length fname $256;

infile dirlist length=reclen ;

input fname $varying256. reclen ;

      run;

      proc print data = dirlist;

run;

data all_cint (drop=fname);

  length myfilename $50;

  set dirlist;

  filepath = "&dirname\"||fname;

  infile dummy filevar = filepath length=reclen end=done missover firstobs=2 dlm=',' dsd lrecl=32767 ;

  do while(not done);

    myfilename = filepath;

[followed by input names]

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Have you looked into DBSASTYPE option with a libname method of importing?

View solution in original post

1 REPLY 1
Reeza
Super User

Have you looked into DBSASTYPE option with a libname method of importing?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 4863 views
  • 0 likes
  • 2 in conversation