The SAS Output Delivery System and reporting techniques

produce docx file

Reply
Frequent Contributor
Posts: 94

produce docx file

Hi,

 

    We are required to produce .docx files with SAS. I searched on web and did not find a good solution. Does anyone help me to figure it out? 

 

Thanks

Super User
Super User
Posts: 9,193

Re: produce docx file

Posted in reply to Niugg2010

Why the docx requirement?  We always output to RTF which is plain text with markup which Word can read just fine, and is portable and readable by anything, much better.  As for creating M$ Proprietary DOCX file format, I don't know of a direct way from SAS, Word is pretty awful to use, even worse than Excel.  Use RTFand if necessary SaveAs from Word when it has opened the RTF.

Super User
Posts: 5,824

Re: produce docx file

Posted in reply to Niugg2010

The "best" in terms of possibility of personalization would be using Add.-in for MS Office.

Using RTF ODS destination is another alternative (there are probably more).

Data never sleeps
Frequent Contributor
Posts: 94

Re: produce docx file

AC need to compile the finall files, so they asked for using docx format, instead of doc and rtf. I guess for AC docx is easy for compiling with new version of word.

Super User
Super User
Posts: 9,193

Re: produce docx file

Posted in reply to Niugg2010

AC?   I would check the requirement, RTF should be compilable with other file no problem, as I said, RTF is well accepted by Word.  As for final compilation, from my understanding PDF is preferred by almost everyone, at least in my industry, and it should matter what file format, you just print to PDF.

Frequent Contributor
Posts: 94

Re: produce docx file

AC: Administrative Coordinator

I find to a way by using VBA to convert doc to docx. However I like to use SAS to produce docx files directly if possible.

Does someone know how to use sas to produce docx files directlly?

Super User
Posts: 12,996

Re: produce docx file

Posted in reply to Niugg2010

Niugg2010 wrote:

AC: Administrative Coordinator

I find to a way by using VBA to convert doc to docx. However I like to use SAS to produce docx files directly if possible.

Does someone know how to use sas to produce docx files directlly?


If you can use VBA to convernt doc to docx then you should be able to convert RTF to docx just as easily.

Frequent Contributor
Posts: 94

Re: produce docx file

Yes. You are correct. 

Super User
Posts: 22,820

Re: produce docx file

Posted in reply to Niugg2010

At present, SAS doesn't offer a way to create DOCX files directly. You can create an RTF file using ODS RTF and then using a VB script to convert the RTF file into a DOCX. If you system allows X command, SAS can call the VB Script as well. 

 

Or you could combine them into PDF which is what I suspect the end product may be. 

 

If you have the Add In for Microsoft you can likely build the report in word and create the DOCX file, but I suspect that's a lot more difficult than ODS RTF. 

 

 

SAS Super FREQ
Posts: 9,253

Re: produce docx file

Posted in reply to Niugg2010

Hi:

  A .DOCX file is really a zip archive that holds XML files that describe your document. So a .DOCX file is not one file, it is a collection of files that conform to the new Microsoft XML standard for describing Word docs.

 

  SAS creates RTF -- not Microsoft proprietary XML as .DOCX. If you need to convert an RTF file to .DOCX, then write the RTF file to a folder and convert it to .DOCX using VBScript or some other process.

 

  You can prove to yourself that a DOCX file is a zip archive by doing this:

1) make a Word document and save it as .DOCX

2) close Word and find the file in Windows Explorer and rename the file from .DOCX

3) Rename the file to .ZIP -- click yes when you get the warning about changing the file extension

4) Open the renamed file with WinZip or a utility that will allow you to explore the folder trees

5) Explore the structure of the zip archive folders -- you will see a lot of XML files

6) You will find the main text of your document in the document.xml file inside the archive

 

  Here are screenshots that illustrate the process --split into 2 images --

_1_make_docx.png

 

Then:

docx_is_zip_archive.png

 

  Most companies generate RTF files with SAS and then either resave them to .DOCX before editing or combine multiple RTF files in Word and then save as .DOCX after editing.

 

  Note that there was NO SAS programming involved in the above process. The only applications used were Word, Windows Explorer, WinZip and Notepad.

 

cynthia

Frequent Contributor
Posts: 94

Re: produce docx file

Posted in reply to Cynthia_sas

Great thanks. Understand.

Ask a Question
Discussion stats
  • 10 replies
  • 692 views
  • 0 likes
  • 6 in conversation