I am plotting some data using BY GROUP option. While I am able to use #byval option to automatically put BY GROUP value in title of each plot, but I want to save each plot individually and want to name it after #byval instead of calling it - SGPLOT01, SGPLOT02 ...
e.g. Lets say I have:
data xyz;
input type$ x y1 y2@@;
cards;
A 1 5 7
A 2 7 9
A 3 8 10
B 1 5 7
B 2 7 9
B 3 8 10
;;
RUN;
PROC SGPLOT DATA=xyz;
by type;
series1 x=x y=y1/markers;
series2 x=x y=y2/markers;
title "#byval";
RUN;
In this example, two plots will be created one each for type A and B. But program will automatically name them as SGPLOT1.pdf and SGPLOT2.pdf. I would rather want to name them A.pdf and B.pdf, and want to save them to directory "C:/SGPLOTS/".
Thanks for your help.
One option is to use ODS and put use a macro to print each TYPE separately, like in the following example.
data xyz;
input type$ x y1 y2 @@;
cards;
A 1 5 7
A 2 7 9
A 3 8 10
B 1 5 7
B 2 7 9
B 3 8 10
;
RUN;
ods listing close;
%macro plot_it(type=);
goptions reset
device = sasprtc
target = sasprtc
;
ods pdf file="C:/SGPLOTS/&type..pdf" notoc;
PROC SGPLOT DATA=xyz;
by type;
where type = "&type";
series x=x y=y1/markers;
series x=x y=y2/markers;
title "#byval";
RUN;
ods pdf close;
%mend plot_it;
%plot_it(type=A);
%plot_it(type=B);
You want to add the variable name within parentheses, after #BYVAL. In this example you want to put #byval(type) in your title.
I have put your example within something SAS calls an "HTML sandwich," which is two lines on top and two lines on the bottom. In addition I added the helpbrowser option, which tells SAS to use its own capabilities to display the html output.
option helpbrowser=sas;
/**** top of html sandwich *****/
ods html ;
ods graphics on;
/*******************************/
data xyz;
input type$ x y1 y2@@;
cards;
A 1 5 7
A 2 7 9
A 3 8 10
B 1 5 7
B 2 7 9
B 3 8 10
;;
RUN;
PROC SGPLOT DATA=xyz;
by type;
series x=x y=y1/markers;
series x=x y=y2/markers;
title "Here is the type: #byval(type)";
RUN;
/**** bottom of html sandwich *****/
ods graphics off;
ods html close;
/**********************************/