I'm using SAS v9.4
I am trying to write a macro that reads a word template, makes some modifications, then saves the new document as a .docx file. I have managed to get it to work for saving to a .doc file, but when I change the extension I get the following error:
Incompatible File Type and File Extension
Does anyone know how I can save files as docx or if that's even possible? Any help would be appreciated
Code is below:
filename sas2word dde 'winword|system';
%macro setupWd(outfile);
options noxsync noxwait xmin;
/* Open Blank Word Document */
data _null_;
length fid rc start stop time 8;
fid=fopen('sas2word','s');
if (fid le 0) then do;
rc=system('start winword');
start=datetime();
stop=start+1;
do while (fid le 0);
fid=fopen('sas2word','s');
time=datetime();
if (time ge stop) then fid=1;
end;
end;
rc=fclose(fid);
run;
/* Save to given location */
data _null_;
file sas2word;
put '[FileSaveAs.Name="' "&outfile" '",.Format=0]';
run;
%mend setupWd;
Works:
%setupWd(outfile = M:\SAS\Output\MacroTest.doc)
Doesnt Work:
%setupWd(outfile = M:\SAS\Output\MacroTest.docx)