BookmarkSubscribeRSS Feed
Philmingo
Fluorite | Level 6

I am using SAS Enterprise Guide 6.1 (64 bit).  

 

I would like my program to stop running and send me an error message (via email) when a macro enabled Excel file is in use.  I already have the error message written out as a macro for other errors that I encounter in my code.  The error message macro is called "err_email".  For other errors, I am using the "syserr" values to determine when to stop my code using the "abort cancel" statement and it works just fine.  

 

What I've discovered is that even though there is an error in the log (because the file is already open and can't be used by the SAS program), the syserr value is still 0 which equates to no error and the program continues to run without getting the needed information from the macro enabled Excel file.  It continues to run for hours until it gets to the end.  Only when checking the log do I discover the error.  I've looked into using the ERRORCHECK= STRICT and ERRORABEND options together, but it just stops the program and doesn't notify me via the error message macro.  

 

Here is the piece of code that pulls in the table from the workbook:

 

%macro price_tag;
libname myxls OleDB 
        init_string="Provider=Microsoft.ACE.OLEDB.12.0;
		data source = &Inputs;
		extended Properties=Excel 12.0";

	data Recon_fx;
		set myxls.'Inp_Plan_Map_SAS'n;
	%runquit;
libname myxls clear; %mend price_tag;

Where %runquit is the macro that indicates whether or not to issue an error message or warning message based on the syserr value and stop the code from running.  It works in all other instances other than if a file is opened by another user.  Password protecting the Excel file is not feasible as many people use the file.  This file gets used at different points when the code is run.  

 

Here are the error messages in the log if that helps:

 

ERROR: Error trying to establish connection: Unable to Initialize: The Microsoft Access database engine cannot open or write to the
file ''. It is already opened exclusively by another user, or you need permission to view and write its data.
ERROR: Error in the LIBNAME statement.

ERROR: Libref MYXLS is not assigned.

4 REPLIES 4
SASKiwi
PROC Star

What version of SAS are you using? We are on SAS 9.4M2 and we have the same issue. A locked Excel file should trigger the OBS = 0 rule setting when using the option SYNTAXCHECK. I suspect it is a bug and I will check SAS Notes when I have some spare time.

Philmingo
Fluorite | Level 6

I am using SAS Enterprise Guide 6.1 (64-bit).  When I add the Syntaxcheck option it does stop my code, but the error message macro doesn't kick off so I don't get an error message email to notify me that it stopped running.  

Tom
Super User Tom
Super User

If it is the LIBNAME that is causing the error then why not just check the SYSLIBRC automatic variable?

Philmingo
Fluorite | Level 6

I am unfamiliar with this variable.  I tried using it as follows but it did not work properly.  It sent an email when the file was open but also when it was not open.  Let me know if this logic makes sense.  

%macro price_tag;
libname myxls OleDB 
        init_string="Provider=Microsoft.ACE.OLEDB.12.0;
		data source = &Inputs;
		extended Properties=Excel 12.0";

	data Recon_fx;
		set myxls.'Inp_Plan_Map_SAS'n;
                if syslibrc ne 0 then %err_email;
	%runquit;libname myxls clear;
%mend price_tag;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 937 views
  • 0 likes
  • 3 in conversation