Save Word files as DOCX using SAS DDE












1














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:SASOutputMacroTest.doc)


Doesnt Work:



%setupWd(outfile = M:SASOutputMacroTest.docx)









share|improve this question




















  • 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
    Dec 28 '18 at 1:06










  • 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 :P
    – RAB
    Dec 28 '18 at 1:19






  • 2




    Not a SAS question. That is a WORD function that the SAS code is calling.
    – Tom
    Dec 28 '18 at 1:22












  • Yeah soz, didn't know which was best to tag so I did both
    – RAB
    Dec 28 '18 at 1:29






  • 1




    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
    Dec 29 '18 at 20:12
















1














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:SASOutputMacroTest.doc)


Doesnt Work:



%setupWd(outfile = M:SASOutputMacroTest.docx)









share|improve this question




















  • 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
    Dec 28 '18 at 1:06










  • 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 :P
    – RAB
    Dec 28 '18 at 1:19






  • 2




    Not a SAS question. That is a WORD function that the SAS code is calling.
    – Tom
    Dec 28 '18 at 1:22












  • Yeah soz, didn't know which was best to tag so I did both
    – RAB
    Dec 28 '18 at 1:29






  • 1




    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
    Dec 29 '18 at 20:12














1












1








1


2





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:SASOutputMacroTest.doc)


Doesnt Work:



%setupWd(outfile = M:SASOutputMacroTest.docx)









share|improve this question















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:SASOutputMacroTest.doc)


Doesnt Work:



%setupWd(outfile = M:SASOutputMacroTest.docx)






ms-word sas






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 0:17









K.Dᴀᴠɪs

6,956112239




6,956112239










asked Dec 28 '18 at 0:16









RAB

712115




712115








  • 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
    Dec 28 '18 at 1:06










  • 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 :P
    – RAB
    Dec 28 '18 at 1:19






  • 2




    Not a SAS question. That is a WORD function that the SAS code is calling.
    – Tom
    Dec 28 '18 at 1:22












  • Yeah soz, didn't know which was best to tag so I did both
    – RAB
    Dec 28 '18 at 1:29






  • 1




    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
    Dec 29 '18 at 20:12














  • 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
    Dec 28 '18 at 1:06










  • 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 :P
    – RAB
    Dec 28 '18 at 1:19






  • 2




    Not a SAS question. That is a WORD function that the SAS code is calling.
    – Tom
    Dec 28 '18 at 1:22












  • Yeah soz, didn't know which was best to tag so I did both
    – RAB
    Dec 28 '18 at 1:29






  • 1




    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
    Dec 29 '18 at 20:12








1




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
Dec 28 '18 at 1:06




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
Dec 28 '18 at 1:06












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 :P
– RAB
Dec 28 '18 at 1:19




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 :P
– RAB
Dec 28 '18 at 1:19




2




2




Not a SAS question. That is a WORD function that the SAS code is calling.
– Tom
Dec 28 '18 at 1:22






Not a SAS question. That is a WORD function that the SAS code is calling.
– Tom
Dec 28 '18 at 1:22














Yeah soz, didn't know which was best to tag so I did both
– RAB
Dec 28 '18 at 1:29




Yeah soz, didn't know which was best to tag so I did both
– RAB
Dec 28 '18 at 1:29




1




1




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
Dec 29 '18 at 20:12




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
Dec 29 '18 at 20:12












1 Answer
1






active

oldest

votes


















2














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






share|improve this answer

















  • 1




    Thanks Heaps! Also the higher in number you to they are just all .txt after 2
    – RAB
    Dec 28 '18 at 1:57






  • 1




    DOCX isn't an option because DDE and this style of commands predates the existence of DOCX.
    – Reeza
    Dec 29 '18 at 20:13











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53952290%2fsave-word-files-as-docx-using-sas-dde%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














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






share|improve this answer

















  • 1




    Thanks Heaps! Also the higher in number you to they are just all .txt after 2
    – RAB
    Dec 28 '18 at 1:57






  • 1




    DOCX isn't an option because DDE and this style of commands predates the existence of DOCX.
    – Reeza
    Dec 29 '18 at 20:13
















2














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






share|improve this answer

















  • 1




    Thanks Heaps! Also the higher in number you to they are just all .txt after 2
    – RAB
    Dec 28 '18 at 1:57






  • 1




    DOCX isn't an option because DDE and this style of commands predates the existence of DOCX.
    – Reeza
    Dec 29 '18 at 20:13














2












2








2






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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 28 '18 at 1:28









Anna Burn

1569




1569








  • 1




    Thanks Heaps! Also the higher in number you to they are just all .txt after 2
    – RAB
    Dec 28 '18 at 1:57






  • 1




    DOCX isn't an option because DDE and this style of commands predates the existence of DOCX.
    – Reeza
    Dec 29 '18 at 20:13














  • 1




    Thanks Heaps! Also the higher in number you to they are just all .txt after 2
    – RAB
    Dec 28 '18 at 1:57






  • 1




    DOCX isn't an option because DDE and this style of commands predates the existence of DOCX.
    – Reeza
    Dec 29 '18 at 20:13








1




1




Thanks Heaps! Also the higher in number you to they are just all .txt after 2
– RAB
Dec 28 '18 at 1:57




Thanks Heaps! Also the higher in number you to they are just all .txt after 2
– RAB
Dec 28 '18 at 1:57




1




1




DOCX isn't an option because DDE and this style of commands predates the existence of DOCX.
– Reeza
Dec 29 '18 at 20:13




DOCX isn't an option because DDE and this style of commands predates the existence of DOCX.
– Reeza
Dec 29 '18 at 20:13


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53952290%2fsave-word-files-as-docx-using-sas-dde%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas