问题
office excel 2016 for some reason does not support DDE command and therefore the following programs is crashing. Do you know how can I make it work? I have tried with proc export, I will add the code I tried as comment. Or if you have any other idea of how it can work, please share. Thank you in advance!
ods listing close;
ODS HTML path="path'
(TITLE="CD");
title;footnote;
%macro prnt;
%if &nobs ne 0 %then %do;
title1 "CDTC";
footnote "PROGRAM: (, UPDATED: &tist";
proc print data = dag.dc label noobs; run;
%end;
ods HTML close;
ods listing;
%mend;
%prnt;
/*
proc export data = inter
outfile =
"\\sraw.xlsx"
dbms = xlsx
replace;
run;
*/
options noxwait noxsync;
%SYSEXEC "C:\Program Files (x86)\Microsoft Office\Office14\excel.exe";
%sysexec "C:\Program Files (x86)\Microsoft Office\root\Office16\excel.exe";
data _null_;
x=sleep(10);
run;
filename Commands dde 'excel|system';
/*Open file and unprotect*/
DATA _null_;
FILE commands;
PUT '[ERROR(FALSE)]';
*Put '[open("\\PATH.xlsx")]';
put '[open("PATH")]';
/*put '[workbook.activate("sheet1")]';*/
Put '[PROTECT.DOCUMENT(FALSE, FALSE, , FALSE, FALSE)]';
RUN;
%LET ARK=sheet1;
%LET RU=4;
filename C1 dde "EXCEL|&ARK!R&RU.C1:R1000C1" NOTAB;
filename C2 dde "EXCEL|&ARK!R&RU.C2:R1000C2" NOTAB;
filename C3 dde "EXCEL|&ARK!R&RU.C3:R1000C3" NOTAB;
filename C4 dde "EXCEL|&ARK!R&RU.C4:R1000C4" NOTAB;
filename C5 dde "EXCEL|&ARK!R&RU.C5:R1000C5" NOTAB;
filename C6 dde "EXCEL|&ARK!R&RU.C6:R1000C6" NOTAB;
filename C7 dde "EXCEL|&ARK!R&RU.C7:R1000C7" NOTAB;
filename C8 dde "EXCEL|&ARK!R&RU.C8:R1000C8" NOTAB;
filename C9 dde "EXCEL|&ARK!R&RU.C9:R1000C9" NOTAB;
filename C10 dde "EXCEL|&ARK!R&RU.C10:R1000C10" NOTAB;
filename C11 dde "EXCEL|&ARK!R&RU.C11:R1000C11" NOTAB;
filename C12 dde "EXCEL|&ARK!R&RU.C12:R1000C12" NOTAB;
filename C13 dde "EXCEL|&ARK!R&RU.C13:R1000C13" NOTAB;
filename C14 dde "EXCEL|&ARK!R&RU.C14:R1000C14" NOTAB;
filename C15 dde "EXCEL|&ARK!R&RU.C15:R1000C15" NOTAB;
filename C16 dde "EXCEL|&ARK!R&RU.C16:R1000C16" NOTAB;
filename C17 dde "EXCEL|&ARK!R&RU.C17:R1000C17" NOTAB;
filename C18 dde "EXCEL|&ARK!R&RU.C18:R1000C18" NOTAB;
filename C19 dde "EXCEL|&ARK!R&RU.C19:R1000C19" NOTAB;
DATA _NULL_;
SET INTER;
FILE C1;
PUT COLLATAGREEMENTID;
FILE C2;
PUT CCYID;
FILE C3;
PUT TYPE;
FILE C4;
PUT AGREEMENTNO;
FILE C5;
PUT WSSCUSTID;
FILE C6;
put receffective $12.;
*PUT RECEFFECTIVE commax32.2;
FILE C7;
PUT RECINDEX;
FILE C8;
PUT RECEFFRATE;
*PUT RECEFFRATE commax32.5;
FILE C9;
PUT RECACCRUAL;
*PUT RECACCRUAL commax32.2;
FILE C10;
PUT DELIVEFFECTIVE;
*PUT DELIVEFFECTIVE commax32.2;
FILE C11;
PUT DELIVINDEX;
FILE C12;
PUT DELIVEFFRATE;
*PUT DELIVEFFRATE commax32.5;
FILE C13;
PUT DELIVACCRUAL;
*PUT DELIVACCRUAL commax32.2;
FILE C14;
PUT TOTEFFECTIVE;
*PUT TOTEFFECTIVE commax32.2;
FILE C15;
PUT TOTACCRUAL;
*PUT TOTACCRUAL commax32.2;
FILE C16;
PUT PRODDATE;
FILE C17;
PUT ENDDATE ;
FILE C18;
PUT FIXED_BAL_EUR;
*PUT FIXED_BAL_EUR commax32.2;
FILE C19;
PUT ON_BAL_EUR;
*PUT ON_BAL_EUR commax32.2;
RUN;
/*TVI 23-09-2016
data _null_;
a='[SAVE.AS('||'"'||'\\PATH';
s="&sta2";
b='.xlsX'||'"'||')]';
c=a||s||b;
call symput('b',"'"||c||"'");
run;
*/
data _null_;
a='[SAVE.AS('||'"'||"PATH";
s="&sta2";
b='.xlsX'||'"'||')]';
c=a||s||b;
call symput('b',"'"||c||"'");
run;
%put &b;
%let savefile= &b;
dATA _NULL_;
FILE COMMANDS lrecl=1024;
PUT '[ERROR(FALSE)]';
PUT &SAVEFILE;
run;
/*lukker excel ned igen*/
DATA _NULL_;
FILE COMMANDS;
PUT '[QUIT()]';
RUN;
QUIT;
回答1:
I had EXACTLY this same problem. The problem is the registry settings for excel 2016 DDE.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel\Options]
"DontUpdateLinks"=dword:00000000
"DDEAllowed"=dword:00000000
"DDECleaned"=dword:00000000
save this in a file.reg and merge with registry, close and restart exccel
回答2:
Proc EXPORT
can replace an entire sheet in an existing workbook. Your template workbook appears to want data starting in row 4. Not knowing what are in the first three rows I would say you probably need to update the template to work with a data-only sheet.
Example, create a multi-sheet workbook, then replace one of the worksheets.
Create template (once) for demo purposes;
filename TEMPLATE 'c:\temp\demo-template.xlsx' recfm=n;
data _null_;
rc = FDELETE ('TEMPLATE');
run;
proc export data=sashelp.class(obs=0) dbms=excel replace file=TEMPLATE;
sheet = 'DATA_FOR_TEMPLATE';
run;
proc export data=sashelp.cars(obs=10) dbms=excel replace file=TEMPLATE;
sheet = 'CARS_DATA';
run;
Now update one sheet in the template, pre-copied to your save/as
filename REALIZE1 'c:\temp\demo-15feb2018.xlsx' recfm=n;
* copy template to desired 'save/as';
data _null_;
rc = FCOPY ('TEMPLATE', 'REALIZE1');
run;
* replace all of a sheet;
proc export data=sashelp.class dbms=excel replace file=REALIZE1;
sheet = 'DATA_FOR_TEMPLATE';
run;
filename TEMPLATE;
filename REALIZE;
For the case of a template with protections that need to be turned off and on, you can do that in a powershell script or excel vb.
来源:https://stackoverflow.com/questions/48802741/change-from-dde-to-proc-export-because-office-2016-does-not-support-it