BookmarkSubscribeRSS Feed
kellyA
Calcite | Level 5

I need to read in a ~40 spreadsheet excel file.  I found this macro posted on another forum, which has been incredible helpful-

%macro imp (insheet=);

    proc import out=work.&insheet

    datafile= "filename.xls"

    dbms=excel replace;

    sheet="&insheet.$";

    getnames=YES; mixed=NO;

    scantext=YES;

    usedate=YES;

    scantime=YES;

%mend imp;

However, I need to add in "guessingrows=500;" but the macro fails every time I include it. Now the macro looks like this-

%macro impb (insheet=);

    proc import out=work.&insheet

    datafile= "filename.xls"

    dbms=excel replace;

    sheet="&insheet.$";

    getnames=YES; mixed=NO;

    guessingrows=500;

    usedate=YES;

    scantime=YES;

%mend impb;

And error messages look like this-

NOTE: The previous statement has been deleted.

NOTE: The previous statement has been deleted.

ERROR 180-322: Statement is not valid or it is used out of proper order.

I've searched around and can't figure out why the macro no longer works.  Obviously it looks like is has something to do with the order, but I have moved the guessingrows statement to no success.  Thoughts?  Thanks in advance for your help!

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,


Guessingrows is not an option for xls imports.  Have a look at this recent post on the subject: https://communities.sas.com/thread/57776

Alternatively you could write a small vba macro to save all the excel files to delimited and then read that in with a datastep, which gives you full control over the data.  I posted an example vba macro some time back, will see if I can find it.

Something like this: http://spreadsheetpage.com/index.php/tip/getting_a_list_of_file_names_using_vba/

Just add in a line for SaveAs :filetype=...

Then run that in Excel and select your folder of Excel files.

kellyA
Calcite | Level 5

Hello

Thank you!  That explains a lot.

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 2 replies
  • 2260 views
  • 0 likes
  • 2 in conversation