由DDE改成proc export 因为office 2016不支持

Change from DDE to proc export because office 2016 does not support it

office excel 2016 由于某些原因不支持 DDE 命令,因此以下程序崩溃。你知道我怎样才能让它发挥作用吗?我已经尝试过 proc 导出,我将添加我尝试过的代码作为注释。或者,如果您对它的工作原理有任何其他想法,请分享。提前致谢!

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 .;
*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;

Proc EXPORT 可以替换现有工作簿中的整个 sheet。您的模板工作簿似乎需要从第 4 行开始的数据。不知道前三行中的内容我会说您可能需要更新模板以使用仅数据 sheet.

例如,创建一个多sheet工作簿,然后替换其中一个工作sheet。

为演示目的创建模板(一次);

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;

现在在模板中更新一个sheet,预先复制到你的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;

对于需要关闭和打开保护的模板,您可以在 powershell 脚本或 excel vb.

中执行此操作

我也遇到过同样的问题。 问题是 excel 2016 DDE 的注册表设置。

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Office.0\Excel\Options]
"DontUpdateLinks"=dword:00000000
"DDEAllowed"=dword:00000000
"DDECleaned"=dword:00000000

将其保存在 file.reg 中并与注册表合并,关闭并重新启动 exccel