08-22-2016 05:56 AM - edited 08-22-2016 08:03 AM
I have an issue when using DDE.
What is happening is I make a copy of my EXCEL master file (example.xls) using SAS, I then open this copied EXCEL file using SAS, then simply close it. That's it, howerver the master EXCEL file (i.e. the one I copied) for reason is locked and when I open it, its says "Read Only" at the top until I close my entire EXCEL process. I'm not sure why this is happening. Below is my code.
%let inpath=C:\; %let infile=example; %let extension=xls; %sysexec copy "&inpath.\&infile..&extension." "%sysfunc(getoption(work))\&sysuserid._&infile..&extension."; ** Get EXCEL commands; filename cmdexcel DDE 'EXCEL|SYSTEM'; data _null_; ** Open EXCEL command; fid = fopen('CMDEXCEL', 'S'); if (fid=0) then do; ** Open EXCEL; rc = system("Start Excel"); start = datetime(); stop = start + 10; ** 10sec limit; end; do while (fid eq 0); fid = fopen('CMDEXCEL', 'S'); time = datetime(); if time ge stop then fid = -1; end; if fid lt 0 then put 'ERR' "OR: Excel failed to open (within time limit)."; run; data _null_; ** Open file **; call system ("'%sysfunc(getoption(work))\&sysuserid._&infile..&extension.', 0, true"); x = sleep(1); run; filename cmdexcel clear; filename cmdexcel DDE 'EXCEL|SYSTEM'; ** Close EXCEL file; data _null_; file cmdexcel; x=sleep(3); put '[error(false)]'; put '[CLOSE(false)]'; run; filename cmdexcel clear; %sysexec del "%sysfunc(getoption(work))\&sysuserid._&infile..&extension.";
All I need is to ensure the master EXCEL file does not lock and does in fact close (well it technically should never open because I use a copied file).
Running SAS 9.4 on windows.
08-22-2016 06:25 AM
I am not surprised you are having difficultie with DDE, it is over 20 years old and not supported anymore by MS. If you really need to use Excel (and that is really your problem there in a nutshell), why not just execute a system copy command to copy the file over. Or import the file and write it out again after processing. Or use VBA to load CSV data from SAS, process into your template file and then save to a new file. There are many options and all of the are better than old unsupported technology.
08-22-2016 06:41 AM
I agree, DDE is redundent technology I would rather use PROC SQL but that requires a lisence I do not have.
The copy is done in the %SYSEXEC lines without a problem, my issue is somehow my file is remaining open, when I dont even open it
08-22-2016 06:49 AM
Errm, proc sql is a querying language, it doesn't create Excel files or anything like that. By create them I meant use tagsets like excelxp, or the newer libname excel engine.
If the copy is done fine using %sysexec, then why are we taling about DDE? Please clarify the problem, exactly what you are doing. As DDE/Excel does not need to be used at all if its just copying a file with the system commands. It sounds like you have other issues.
08-22-2016 06:55 AM
FALSE or 0 are correct.
QUIT closes all EXCEL process but this means other EXCEL files I have open.
Not necessarily, you can have multiple apps of Excel open at once AFAIK.
I don't know why you reset your filename reference but it seems unnecessary.
But you use a different method to open/close your process than I typically use.
Slide 20 is the code I usually use. As of last week
This is all based on the assumption that it's DDE and not Excel. Another issue with this process is Trist Center settings. So basically perform each step manually and see if you get any errors.
08-22-2016 07:42 AM
Thanks for your comments, I tired you method and got this message
ERROR: Physical file does not exist, EXCEL|SYSTEM.
However I checked and the file did exists, below is the code.
options noxwait noxsync; %put %sysfunc(getoption(work)); ** Make copy; %sysexec copy "&inpath.\&infile..&extension." "%sysfunc(getoption(work))\&sysuserid..&extension."; ** Open EXCEL; x "C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.EXE"; ** Wait for EXCEL to open; data _null_; x=sleep(3); run; ** Get EXCEL commands; filename cmdexcel DDE 'EXCEL|SYSTEM'; ** Open EXCEL file; data _null_; file cmdexcel; put "[open(""%sysfunc(getoption(work))\&sysuserid..&extension."")]"; x=sleep(3); run; ** Clsoe EXCEL process; data _null_; put '[close()]'; put '[quit()]'; run; ** Delete copy; %sysexec del "%sysfunc(getoption(work))\&sysuserid..&extension.";
08-22-2016 09:58 AM
** Open EXCEL file; data _null_; file cmdexcel; put "[open(""%sysfunc(getoption(work))\&sysuserid..&extension."")]"; x=sleep(3); run;
The above bit
08-22-2016 01:45 PM
Run your code with MPRINT and SYMBOLGEN on and post the log from that section. The log should explain why the process can't find that file.
09-07-2016 04:45 PM