What is the most efficient way to prepare a report using SAS? I usually created Figures and Tables, copy them into a Word document, and create the report there. I wonder if there is a more efficient way for that. For example, where I write the code I add comments, titles for Tables and Figures, and when I run the whole program I also have my report ready.
Thank you!
I would do this either using ODS WORD (experimental), ODS LATEX or a Jupyter Notebook.
There's also RWI but that seems complicated.
In order of maturity it's Latex, Jupyter, Word.
Note these are not your only options but the most viable options IMO.
@Emma_at_SAS wrote:
What is the most efficient way to prepare a report using SAS? I usually created Figures and Tables, copy them into a Word document, and create the report there. I wonder if there is a more efficient way for that. For example, where I write the code I add comments, titles for Tables and Figures, and when I run the whole program I also have my report ready.
Thank you!
I would do this either using ODS WORD (experimental), ODS LATEX or a Jupyter Notebook.
There's also RWI but that seems complicated.
In order of maturity it's Latex, Jupyter, Word.
Note these are not your only options but the most viable options IMO.
@Emma_at_SAS wrote:
What is the most efficient way to prepare a report using SAS? I usually created Figures and Tables, copy them into a Word document, and create the report there. I wonder if there is a more efficient way for that. For example, where I write the code I add comments, titles for Tables and Figures, and when I run the whole program I also have my report ready.
Thank you!
Thank you, Reeza, for your prompt response!
Do you have a suggestion for where to start. I am planning to start from here:
https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3235-2019.pdf
but appreciate any suggestions.
Thank you!
Too often, the question is 'how to I get SAS to do XYZ?'. That implies a PUSH operation from SAS. turn the question on its head and ask how do I get my data, from SAS processing, into Word using a PULL operation. Execute and pull SAS from Word using a variety of techniques. I often execute SAS programs and retrieve the data w/o using anything more than SAS via Integration Technologies.
So, how do you do a PULL operation? Look at articles by Chris Hemendinger on VBA or C# doing it. Use Examples from Excel as well since they are very similar. i also have a complete example on gihub. (see: savian-net/ExcelSasDemo (github.com)) for Excel. If you will be using Word, just use the COM dll for Word.
A PULL operation takes a bit of time to get used to but it is, by far, the most powerful way to use SAS and Microsoft products together. Every feature of Microsoft is available as well as SAS. A PUSH operation does not have that advantage.
Let's assume that your SAS datasets are already created. Download the SAS ODBC driver and install it. You could also use OleDb. Go into Word VBA, for now, and read an ODBC datasource. The SAS data will be available using a simple ODBC query. Loop through the data and write it to a figure/table/text/etc.
This is the entry method for doing this kind of work. As you progress, it is better to use C# and a 3rd party tool that handles Word (there are lots). That way, you can create Word documents w/o Word being on the machine. If you face a serious enterprise problem (like 10K worksheets a day), VBA doesn't cut it. Ultimately a docx is simply a zip file with XML documents in it. Open source libraries can read/write to them. SAS datasets are ODBC/OleDb compliant. You can read from them.
If you make it to that point, you can also submit SAS code from C#/VBA using SAS/Int Technologies. Then, SAS becomes a child process.
ODS RTF has been in production for a long time, and is another option.
Vince DelGobbo
SAS R&D
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!