我正在尝试编写一个 SAS 程序来通过 DDE 在 excel 文件中进行查找和替换。具体来说,我正在尝试在标题行中搜索字符串之间的空格(即“”)并将它们替换为没有空格(即“”)。
例如,如果我有一个包含“测试名称”的单元格,我想进行查找和替换以使其成为“测试名称”。
这就是我所拥有的:
options noxwait noxsync;
/* Open Excel */
x '"C:\Program Files (x86)\Microsoft Office\Office14\excel.exe"';
filename cmds dde 'excel|system';
data _null_;
x=sleep(5);
run;
/* Open File and Manipulate*/
data _null_;
file cmds;
put '[open("C:\filename.xls")]';
put '[select("R1")]';
put '[formula.replace(" ","",1,,false,false)]';
run;
/*Close File*/
data _null_;
file cmds;
put '[FILE-CLOSE("C:\filename.xls")]';
put '[QUIT()]';
run;
查找和替换功能不起作用。阅读该声明后,我在日志中得到以下信息:
NOTE: The file CMDS is:
DDE Session,
SESSION=excel|system,RECFM=V,LRECL=256
ERROR: DDE session not ready.
FATAL: Unrecoverable I/O error detected in the execution of the DATA step program.
Aborted during the EXECUTION phase.
NOTE: 2 records were written to the file CMDS.
The minimum record length was 21.
The maximum record length was 70.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.63 seconds
cpu time 0.00 seconds
有什么建议么?
另外,有谁知道 formula.replace 语句中的参数是什么?我只知道第一个和第二个是您要查找的内容以及要替换的内容。我正在努力寻找任何文件。