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-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!

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.

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