BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
nelsonc
Fluorite | Level 6

I have a sas program that collects all the data i need but when i try and export it to excel i loose my connection to "local".

this code exports 4 seperate files and will fail after 2 export no matter which two i export. This code has worked before but is not working now. Could this be a firewall issue? Need some help. here is the export code that causes the disconnect. All tables exported are less then 2000 lines.If I run in EG it tells me i lost connection, if i run is base it just closes out after exporting two files and gives no errors.

/*-------------------------------------------------------*/
/*-----------------Export To Excel File------------------*/
/*-------------------------------------------------------*/
PROC EXPORT DATA=BIS_Campaign
OUTFILE= "\\cifs1\blahblahblah\BIS_Campaign.xlsx"
DBMS=EXCEL REPLACE;
SHEET="Sheet1";
NEWFILE=Yes;
RUN;

 

PROC EXPORT DATA=BIS_Sub
OUTFILE= "\\cifs1\blahblahblah\BIS_Subs.xlsx"
DBMS=EXCEL REPLACE;
SHEET="Sheet1";
NEWFILE=Yes;
RUN;

PROC EXPORT DATA=BIS_Wait_Final
OUTFILE= "\\cifs1\blahblahblah\BIS_SubDetail.xlsx"
DBMS=EXCEL REPLACE;
SHEET="Sheet1";
NEWFILE=Yes;
RUN;

PROC EXPORT DATA=BIS_Sent_Final
OUTFILE= "\\cifs1\blahblahblah\BIS_Sent.xlsx"
DBMS=EXCEL REPLACE;
SHEET="Sheet1";
NEWFILE=Yes;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Did you try using DBMS=XLSX so that you are not dependent on any Microsoft products working properly?

View solution in original post

15 REPLIES 15
Tom
Super User Tom
Super User

Did you try using DBMS=XLSX so that you are not dependent on any Microsoft products working properly?

nelsonc
Fluorite | Level 6

I just tried switching it to XLSX and this does work.

However this creates a .bak file for each, is there a way to stop this form creating .bak files without writing a macro to delete the .bak files?

Tom
Super User Tom
Super User

You don't need a macro to delete a file, but you could make one if you want.

You can either remove any existing file before trying to re-create it.

filename outfile "\\cifs1\blahblahblah\BIS_Campaign.xlsx";
%let RC=%sysfunc(fdelete(outfile));
PROC EXPORT DATA=BIS_Campaign OUTFILE=outfile DBMS=XLSX REPLACE;
  SHEET="Sheet1";
  NEWFILE=Yes;
RUN;

Or remove the .bak file afterwards.

NextVersion
Calcite | Level 5

DBMS=XLSX works if you do this programmatically. However if you use the File Import/Export from the SAS Menu the issue remains of SAS Crashing. Is there also a way to change the default behavior that the SAS menu chooses in order to do an Import/Export?

ballardw
Super User

@nelsonc wrote:

I have a sas program that collects all the data i need but when i try and export it to excel i loose my connection to "local".

this code exports 4 seperate files and will fail after 2 export no matter which two i export. This code has worked before but is not working now. Could this be a firewall issue? Need some help. here is the export code that causes the disconnect. All tables exported are less then 2000 lines.If I run in EG it tells me i lost connection, if i run is base it just closes out after exporting two files and gives no errors.

 


Highlighted text tells me it is likely that something changed. One would suspect on your server side. Talk to you SAS Admin about software or settings that may have changed on the server.

 

Sajid01
Meteorite | Level 14

Hello @nelsonc 
Is SAS installed on your local machine and the output destination mapped to your local machine ?
if the answer is yes, then try restarting your machine.

PeteLund
Obsidian | Level 7

I'm having a very similar issue, but using PROC IMPORT with EXCEL rather than EXPORT.  The following code is the result of a macro call, but I have the same issue whether the code is run from the macro call or just run itself:

 

PROC IMPORT OUT= WORK.ComorbidityLabels DATAFILE= "\\coconuts3\data\AlaskaTrauma\ProjectFiles\Control\AnnualReportLabels.xlsx" DBMS=EXCEL REPLACE;
RANGE="ComorbidityLabels$";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;

 

If I run this in EG, where the macro that creates the IMPORT code is generated, I randomly get a "Error: The connection to the server has been lost."  This code has run just fine for many months and just yesterday started acting this way.  The code runs fine in DM.  SAS and all the data are on the same machine.  Using 9.4M7 and EG 8.3.0.103.

Tom
Super User Tom
Super User

Enterprise Guide connects to a SAS server. That message sounds like Enterprise Guide has lost the connection to the SAS server.

 

Have the administrator of the server that the SAS session is running on try to figure out what is happening.  Perhaps the I/O between the server and network disk you are reading from is causing the connection between your PC and the SAS server to not respond quickly enough.  So Enterprise Guide thinks the server is gone.

 

You should probably raise a support ticket with SAS support.

PeteLund
Obsidian | Level 7

As I mentioned in my post, everything, SAS and data, is local (on the same machine).  I'm the "SAS administrator" as it's a PC SAS  license on one workstation.  The job literally takes a fraction of a second to run, returning about 20 rows from the spreadsheet - hardly time for the connection to get hung up.  The main thing though is that this job has run thousands of times and just started doing this yesterday - no changes to SAS or EG installs.  I'm think it's a Microsoft update issue, but am having trouble seeing how this would affect EG differently than DM.

PeteLund
Obsidian | Level 7

I'm amending my earlier post - this does fail in DM as well.  I created a simple two-cell spreadsheet with a "header" row of "Quote" and a data "row" of "Hello World!" in c:\temp\HelloWorld.xlsx and am running PC SAS on the same machine.  In either EG or DM the following code runs just fine once or twice and then fails.  In EG, I get the "Lost connection to server" message and in DM, the session just goes away.  I get the exact same behavior on two different machines.

 

PROC IMPORT OUT= WORK.ComorbidityLabels DATAFILE= "c:\temp\HelloWorld.xlsx" DBMS=EXCEL REPLACE;
RANGE="Sheet1$";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;

 

And a new wrinkle, it's not just PROC IMPORT.  I get similar results using the Excel LIBNAME engine.  This code runs fine two or three times and then fails:

 

libname test excel "c:\temp\HelloWorld.xlsx";

data test;
  set test.'Sheet1$'n;
run;

libname test clear;

 

In EG, sometimes I get the server connection lost message and sometimes a different message, "Error: Integration technologies failed to provide server interface. The remote procedure call failed. (Exception from HRESULT: 0x800706BE)"

 

I'd be interested if anyone can run either of the above a number of times in a row with success on a similar setup: PC SAS 9.4M7 on the local machine, Windows 10 Pro, Office 365.  Again, I have the same issues on two different machines and the real code that exposed the issue has been running unchanged for months and this just popped up this week.

Tom
Super User Tom
Super User

In this case the root cause is probably the DBMS=EXCEL.  The error message is probably talking about some "connection" that the EXCEL engine is making to the Microsoft Excel product that SAS is calling to read/write the XLSX file.

 

Try changing that using DBMS=XLSX and see if the error disappears.

PeteLund
Obsidian | Level 7

XLSX on PROC IMPORT is not really an option for me in the real world as, at least last I checked, it does not support reading from a specific worksheet.  It will always read from the first one and many of the spreadsheet I'm pulling data from have multiple worksheets and I need to reference particular ones.

Tom
Super User Tom
Super User

@PeteLund wrote:

XLSX on PROC IMPORT is not really an option for me in the real world as, at least last I checked, it does not support reading from a specific worksheet.  It will always read from the first one and many of the spreadsheet I'm pulling data from have multiple worksheets and I need to reference particular ones.


That is not true.  You can tell PROC IMPORT which sheet to read from an XLSX file.

PeteLund
Obsidian | Level 7

Thanks Tom - you are correct.  I've always used RANGE with DBMX=Excel and you get away with just referencing a worksheet name (with no range specified) and IMPORT will read the entire sheet.  With DBMS=XLSX the RANGE= statement needs to specify a range, but the SHEET= statement works fine with XLSX to read the whole sheet.

 

While this does work, I've tracked down about 150 places in my code I've used DBMS=Excel that might have issues.  Fortunately, the IMPORT always works when just called once, so often not a real issue.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 15 replies
  • 3023 views
  • 1 like
  • 6 in conversation