0
votes

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)
1
Just changing the name doesn't change the format of the file. What are the possible values for the FORMAT= option of the FileSaveAs method you are calling?Tom
That's a good point, and honestly no idea what the options are. SAS isn't most google-friendly of languages, but I'll keep trying :Pmorgan121
Not a SAS question. That is a WORD function that the SAS code is calling.Tom
Yeah soz, didn't know which was best to tag so I did bothmorgan121
DDE is antiquated and really shouldn't be used. Use a VB script instead which is entirely Googleable. DDE isn't google friendly because it predates Google.Reeza

1 Answers

1
votes

Re-write the save bit without the format option:

data _null_; 
   file sas2word;
   put '[FileSaveAs.Name="' "&outfile" '"]';
run;

Alos, the options for Format (in case anyone was wondering) are:

Format = 0: .doc
Format = 1: .dot
Format = 2: .txt

The only way to get .docx is to put it in the file path name and not specify a format