Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
chander_3456
Calcite | Level 5

In my data has 2 treatments, In below code step1,For one treatment I have created 3 plots by proc sgplot and combine them in one plot on PDF  by using proc greplay , but client asked me to create it for another treatment too and the final output in 2 pages by treatment, one and two.
So, In below code step 2, i have created another 3 plots by by proc sgplot , So my question is
1) How can i create 2nd set of plots  to combine them in one plot on PDF  by using proc greplay?
2) once i create 2nd set of PDF with 2nd treatment, how can i combine 1st treatment plot pdf and 2nd treatment plot pdf?

I have used the below code....
/*** Step1-code: for Treatmet 1***/
/***created 3 plots by proc sgplot***/
%* SGPLOT1:
ods graphics on / border=no reset=index imagename='plot1'
proc sgplot data=dataset ;
by trtp;
where trtp="treatment1";
vbarparm category=subjid response=count / fillattrs=(color=green);
yaxis values = (0 to 8 by 1) valueattrs=(weight=bold size=12pt) ;
xaxis display = (novalues) label='';
run;
%* SGPLOT2:
ods graphics on / border=no reset=index imagename='plot2'
proc sgplot data=dataset ;
by trtp;
where trtp="treatment1";
vbarparm category=subjid response=count / fillattrs=(color=green);
yaxis values = (0 to 8 by 1) valueattrs=(weight=bold size=12pt) ;
xaxis display = (novalues) label='';
run;
%* SGPLOT3:
ods graphics on / border=no reset=index imagename='plot3'
proc sgplot data=dataset ;
by trtp;
where trtp="treatment1";
vbarparm category=subjid response=count / fillattrs=(color=green);
yaxis values = (0 to 8 by 1) valueattrs=(weight=bold size=12pt) ;
xaxis display = (novalues) label='';
run;
goptions reset=all noborder device=png300 nodisplay;
goptions noborder iback="&outdir./plot1.png" imagestyle=fit;
proc gslide;
run;
quit;
goptions noborder iback="&outdir./plot2.png" imagestyle=fit;
proc gslide;
run;
quit;
goptions noborder iback="&outdir./plot3.png" imagestyle=fit;
proc gslide;
run;
quit;

ods pdf file="x/swss3_0/table/oncoprint.pdf" title= "&tabno";

proc greplay nofs igout=work.gseg tc=work.tempcat;
tdef spec4
1/ llx=4 lly=71
ulx=4 uly=90
urx=61 ury=90
lrx=61 lry=71

2/ llx=1 lly=10
ulx=1 uly=72
urx=70 ury=72
lrx=70 lry=10

3/ llx=61 lly=10
ulx=61 uly=73
urx=100 ury=73
lrx=100 lry=10

4/ llx=0 lly=0
ulx=0 uly=100
urx=100 ury=100
lrx=100 lry=0;
template spec4;
treplay 1:1 2:2 3:3 4:4;
run;
quit;
ods pdf close;
ods listing;

/***Step2- code: for Treatmet 2***/
/***created 3 plots by proc sgplot***/
%* SGPLOT1:
ods graphics on / border=no reset=index imagename='plot5'
proc sgplot data=dataset ;
by trtp;
where trtp="treatment2";
vbarparm category=subjid response=count / fillattrs=(color=green);
yaxis values = (0 to 8 by 1) valueattrs=(weight=bold size=12pt) ;
xaxis display = (novalues) label='';
run;
%* SGPLOT2:
ods graphics on / border=no reset=index imagename='plot6'
proc sgplot data=dataset ;
by trtp;
where trtp="treatment2";
vbarparm category=subjid response=count / fillattrs=(color=green);
yaxis values = (0 to 8 by 1) valueattrs=(weight=bold size=12pt) ;
xaxis display = (novalues) label='';
run;
%* SGPLOT3:
ods graphics on / border=no reset=index imagename='plot7'
proc sgplot data=dataset ;
by trtp;
where trtp="treatment2";
vbarparm category=subjid response=count / fillattrs=(color=green);
yaxis values = (0 to 8 by 1) valueattrs=(weight=bold size=12pt) ;
xaxis display = (novalues) label='';
run;
goptions reset=all noborder device=png300 nodisplay;
goptions noborder iback="&outdir./plot5.png" imagestyle=fit;
proc gslide;
run;
quit;
goptions noborder iback="&outdir./plot6.png" imagestyle=fit;
proc gslide;
run;
quit;
goptions noborder iback="&outdir./plot7.png" imagestyle=fit;
proc gslide;
run;
quit;

ods pdf file="x/swss3_0/table/oncoprint.pdf" title= "&tabno";

proc greplay nofs igout=work.gseg tc=work.tempcat;
tdef spec5
1/ llx=4 lly=71
ulx=4 uly=90
urx=61 ury=90
lrx=61 lry=71

2/ llx=1 lly=10
ulx=1 uly=72
urx=70 ury=72
lrx=70 lry=10

3/ llx=61 lly=10
ulx=61 uly=73
urx=100 ury=73
lrx=100 lry=10

4/ llx=0 lly=0
ulx=0 uly=100
urx=100 ury=100
lrx=100 lry=0;
template spec5;
treplay 5:5 6:6 7:7 8:8;
run;
quit;
ods pdf close;
ods listing;

 

1 REPLY 1
GraphGuy
Meteorite | Level 14

Since ODS Graphics (sgplot) doesn't directly work with SAS/Graph Proc Greplay (which allows you to combine SAS/Graph graphs), it looks like you're saving the sgplot graphs as images, and then displaying the images in blank SAS/Graph gslides, and 'replaying' them into a custom greplay template to combine them.

 

I would recommend that when you run the gslide commands, use the name= option to give the grseg's specific/non-default names, and then use those names when you treplay the grsegs back into the template. Also, you'll either need to start a fresh SAS session each time you run this job, or delete the grsegs each time you run it - otherwise I think that if the grseg name is already taken, then it will append a number to the name (to get a unique name).

 

Once you have made those enhancements, and have specific/unique names on all your grsegs, I think you should be able to more easily use proc greplay.

 

goptions noborder iback="&outdir./plot1.png" imagestyle=fit;
proc gslide / name='plot1';
run;

goptions noborder iback="&outdir./plot2.png" imagestyle=fit;
proc gslide / name='plot2';
run;

goptions noborder iback="&outdir./plot3.png" imagestyle=fit;
proc gslide / name='plot3';
run;

 

Combine these using ...

treplay 1:plot1 2:plot2 3:plot3;

 

 

goptions noborder iback="&outdir./plot5.png" imagestyle=fit;
proc gslide / name='plot5';
run;

goptions noborder iback="&outdir./plot6.png" imagestyle=fit;
proc gslide / name='plot6';
run;

goptions noborder iback="&outdir./plot7.png" imagestyle=fit;
proc gslide / name='plot7';
run;

 

Combine these using ...

treplay 1:plot5 2:plot6 3:plot7;

 

 

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 719 views
  • 0 likes
  • 2 in conversation