BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Emma_at_SAS
Lapis Lazuli | Level 10

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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!


 

View solution in original post

7 REPLIES 7
Reeza
Super User

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!


 

Emma_at_SAS
Lapis Lazuli | Level 10

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!

Reeza
Super User
That seems like a good start! First I would take a quick overview of all the features you need, ie graphs, centering, alignment, footnotes, page numbers and ensure that ODS WORD had as many as possible. Some can be easy to do manually in Word, ie Table of Contents or Page numbers but somethings, like custom footnotes could be painful if it couldn't be automated. So you want to ensure this will get you to somewhere you're happy with...otherwise you'll get 70% there, realize it won't work and then have to take a different approach. Guess how I learned that 😉
AlanC
Barite | Level 11

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.

https://github.com/savian-net
Reeza
Super User
How does that work when updating data into text? For example, I'll incorporate values into titles and paragraphs that would then get piped straight to Word. I now use RMarkdown which is much simpler but curious as to how a PULL approach would work in that case.
AlanC
Barite | Level 11

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. 

https://github.com/savian-net
Vince_SAS
Rhodochrosite | Level 12

ODS RTF has been in production for a long time, and is another option.

 

Vince DelGobbo

SAS R&D

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Discussion stats
  • 7 replies
  • 1218 views
  • 5 likes
  • 4 in conversation