A common question I’m asked on a regular basis is “How do I save my output?”
With the SAS 9.2 and above we now have the Output Viewer window and our output is automatically created in an HTML format. Much cleaner and easy to copy & paste if you wish. However, let’s see how we can take advantage of ODS (Output Delivery System) to save our output in either a Word format or a PDF file.
Saving as RTF (Rich Text Format) for Word
We are running frequencies and means on data and we would like to save the output into an RTF format.
These are the results we would like to save in an RTF document:
Proc freq data=sample1;
tables agegroup room;
Run;
Proc means data=sample1;
var age income;
Run;
To save the results you need to:
- Call on the ODS
- State the file format for the output
- Designate the location and name of the output file you want to save
- Ensure that the coding for the results you want to save follow the ODS statement
- Close or save the file by closing the ODS destination
ODS rtf file=”d:\Research_output\freq_means.rtf”;
Proc freq data=sample1;
tables agegroup room;
Run;
Proc means data=sample1;
var age income;
Run;
ODS rtf close;
You should now have a file called freq_means.rtf located in the D:\Research_output directory. This is an example ONLY – please ensure that you use directory that exists on your system.
Saving as PDF
You’ll use the same process to save your output as a PDF, except you will replace the RTF with PDF. Using the same coding above as an example:
ODS pdf file=”d:\Research_output\freq_means.pdf“;
Proc freq data=sample1;
tables agegroup room;
Run;
Proc means data=sample1;
var age income;
Run;
ODS pdf close;
To recap:
ods file-format file=”file-location and name.file-format“;
Proc coding for whatever output you’d like to save
ods file-format close;1