SAS to Excel DDE 生成测试但不输出数据

SAS to Excel DDE produces test but not output data

我一直在关注在线文档并浏览其他堆栈溢出查询,但我还没有找到通过 DDE 将我的 SAS 数据集输出到 excel 的方法。

我运行的SAS版本是SAS9.4 excel我是运行的版本是microsoft office 2016 - excel 2016

我用来导出的代码是

/*Excel DDE interface options*/ /*TEST*/
options noxwait noxsync;

X '"C:\Users\user.name\Desktop\template_dde.xlsx"';

data _null_;
    rc=sleep(15);
run;

filename ddedata dde 'excel|SFA!r2c1:r4000c56';

data _null_;
    file ddedata notab;
    set work.Results_output_format end=eof;
put '"THIS IS A TEST"';
run;

%LET timestamp = %SYSFUNC(PUTN(%SYSFUNC(DATE()),yymmddn8.));
%LET hourstamp = %SYSFUNC(COMPRESS(%SYSFUNC(TIME(),time.),%STR( :)));

data _null_;
    length cmnd 0.;
    file ddedata;

    cmnd = '"[save.as("C:\Users\user.name\Desktop\&timestamp._&hourstamp._template_dde.xlsx")]"';
    put cmnd;
    put '[quit()]';
run;

它输出"this is a test"然后输出保存语句但是我的数据没有导出,文件也没有真正保存。

我是不是忽略了什么?

SET 将数据集内容隐式放置在Excel 文件中。您需要使用 PUT 语句将数据添加到工作表。您还需要使用单独的文件名将命令发送到 Excel|system 频道。

您的代码在尝试的宏变量解析周围使用了单引号 -- 这是不正确的。

此代码假定存在一个现有工作簿c:\temp\template_dde.xlsx

* open template in Excel;
X '"C:\Temp\template_dde.xlsx"';

* wait for app to start and file to load;
data _null_; rc=sleep(3); run;

* define filerefs for data transfer and command execution;
filename ddedata dde 'excel|Sheet1!r2c1:r4000c56';
filename ddecmnd dde 'excel|System';

* pump data into excel cells at location specified in ddedata;
data _null_;
  file ddedata ; * <--- removed your NOTAB option, so now I dont have to put '09x' between each variable;

  set sashelp.class;
  put name sex age height weight; 
run;

* Extended ISO timestamp as yyyy-mm-dd_hh-mm-ss;
%let timestamp = %sysfunc(translate(%sysfunc(datetime(),E8601DT),%str(_-),%str(T:)));

* send commands to save workbook and close Excel;
data _null_;
    file ddecmnd;

    put "[save.as(""C:\Temp\&timestamp._template_dde.xlsx"")]";
    put '[quit()]';
run;

关于 DDE 的大量会议论文,例如 "SAS®-with-Excel Application Development: Tools and Techniques"、SUGI 31、LeRoy Bessler、Assurant Health