Saving Output - RhoInc/sas-sgplot GitHub Wiki
Contents
- Setup
- ODS Sandwich
- RhoTables4
- Scalable Vector Graphics
While ODS Graphics facilitate a ton of different ways to capture output, at Rho we generally only have to worry about a few different variations.
Setup
We begin by defining some macro variables and creating a dataset, just to keep things simple below.
%let pgmdir = H:\D2G\OutputCapture;
%let tbl = FIG_TAA;
proc sort data=sashelp.cars out=cars;
by cylinders;
where n(cylinders);
run;
ODS Sandwich
In theory capturing graphs in an RTF file is straightforward.
ods rtf file="&pgmdir\&tbl._pre.rtf";
proc sgplot data=cars;
scatter y=enginesize x=horsepower /
group=cylinders
;
run;
ods rtf close;
In practice we have to put several other fiddly bits before and after the two ods rtf
statements.
*---------- cosmetics ----------;
options
nodate
nonumber
orientation=landscape
;
ods graphics /
outputfmt=png
height=4in
width=8in
noborder
;
*---------- where and what ----------;
ods results off;
ods listing close;
ods rtf file="&pgmdir\&tbl._pre.rtf";
*---------- the plot ----------;
proc sgplot data=cars;
scatter y=enginesize x=horsepower /
group=cylinders
;
run;
*---------- finish ----------;
ods rtf close;
ods listing;
ods results on;
Much of the above is self-explanatory (e.g., noborder
). The items that could stand additional explanation are:
outputfmt=png
- The default output format varies by SAS version. Use this to get a consistent look across versions.
ods listing close;
- This prevents the creation of extraneous files in your directory.
ods results off;
- This prevents pop-ups from halting your job mid-run.
_pre
- We name the resulting file
FIG_TAA_pre.rtf
because it is typically only an intermediate step along the way to creating RhoTables output. Speaking of which...
- We name the resulting file
RhoTables4
We don't usually want an image-only RTF file. Usually we want to add titles and footnotes via RhoTables. Assuming you have just created an RTF file using the ODS sandwich method described above, using RhoTables to add titles and footnotes is not too difficult.
*---------- create a one-record dataset ----------;
data dummy;
x = " ";
run;
*---------- put plot in column 1 using rt4pic ----------;
%let Def1 = COL|1|C|%rt4pic(&pgmdir\&tbl._pre.rtf)|wid(126);
*---------- RhoTables call ----------;
%RhoTables4
(ItemName=&tbl
,ItemType=figure
,Style=Table
,LineSize=126
,PageSize=52
,Data=dummy
);
Gotcha: In RhoTables3 we would pass a zero-record dataset to the macro. In RhoTables4 you must pass a one-record dataset to the macro. Don't worry about why this is the case; just be aware that there is a subtle difference.
Documentation: Assuming you are connected to the Rho network, the RhoTables4 documentation can be found here. The relevant content is in section 13.1.
Scalable Vector Graphics
Scalable Vector Graphics (SVG) is an image format that allows you to zoom in/out on a graph without losing resolution. They are a great image format for publication graphics. The simplest way to generate an SVG graphic is with the imagefmt=pdf
option.
*---------- cosmetics ----------;
ods graphics /
outputfmt=pdf
height=4in
width=8in
noborder
;
*---------- where and what ----------;
ods listing gpath="&pgmdir";
ods graphics / imagename="svgscatter";
*---------- the plot ----------;
proc sgplot data=cars;
scatter y=enginesize x=horsepower /
group=cylinders
;
run;
Zoomed Out
Zoomed In