BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
antor82
Obsidian | Level 7

Dear Friends

 

 

I would like to insert multiple graphs into a single image file.

 

I'm trying to learn template and sgrender .... but it is quite hostile for me!

 

Can anybody help me?

 

Tks in advance!

 

I attach also the codes I used to create each single graph.

(up to now, I have to put them all together on photoshop...)

 

 

proc sgplot data=survivalplotdata;
	step x=time y=survival / lineattrs=(pattern=solid thickness=2);
	xaxistable AtRisk / x=tAtRisk location=inside valueattrs=(size=10) 
		label='Patients at risk' labelattrs=(weight=bold);
	yaxis min=0 label='Probability' 
		labelattrs=(weight=bold);
	xaxis label='Years' labelattrs=(weight=bold);
	Title 'Actuarial survival';
	title2 'with patients at risk';
run;

proc sgplot data=cif_cvm;
	step x=Int_FU_Death y=CIF / lineattrs=(pattern=solid thickness=2);
	xaxistable AtRisk / x=tAtRisk location=inside valueattrs=(size=10) 
		label='Soggetti a rischio' labelattrs=(weight=bold);
	yaxis max=0.20 label='CIF estimate' 
		labelattrs=(weight=bold);
	xaxis label='Years' labelattrs=(weight=bold);
	Title 'Cumulative incidence function of CV mortality';
	title2 'with patients at risk';
run;

proc sgplot data=cif_m3;
	step x=Int_Fu_M3_Redo y=CIF / lineattrs=(pattern=solid thickness=2);
	xaxistable AtRisk / x=tAtRisk location=inside valueattrs=(size=10) 
		label='Patients at risk' labelattrs=(weight=bold);
	yaxis max=0.20 label='CIF estimate' 
		labelattrs=(weight=bold);
	xaxis label='Years' labelattrs=(weight=bold);
	Title 'Cumulative incidence function of MR ≥3+';
	title2 'with patients at risk';
run;

proc sgplot data=cif_redo;
	step x=Int_Fu_M3_Redo y=CIF / lineattrs=(pattern=solid thickness=2);
	xaxistable AtRisk / x=tAtRisk location=inside valueattrs=(size=10) 
		label='Patients at risk' labelattrs=(weight=bold);
	yaxis max=0.20 label='Cumulative incidence function' 
		labelattrs=(weight=bold);
	xaxis label='Years' labelattrs=(weight=bold);
	Title 'Cumulative incidence function of reoperation';
	title2 'with patients at risk';
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Most of the approaches to single image will rely on a single data set to allow the procedure to generate image.

 

Since your plots appear similar I would suspect one approach would be to

1)  get the same x y variable names in each set

2)  combine the data adding a variable to indicate which set each record comes from

3) create a custom format to display the text for the Title statement as the values of a format for the data set indicator variable

4) use SGPANEL with the combined data, use a PANELBY statement using the data set indicator variable with desired options,

   options would likely be Rows=2 Columns=2 ONEPANEL if you want a 2 by 2 layout.

5) use COLAXISTABLE instead of xaxistable

6) a COLAXIS statement that looks pretty similar to your XAXIS statement.

 

use the custom format for the dataset indicator variable. That should become the label for each section of the panel graph.

 

Combining and renaming the data is not that difficult. Below is a generic example:

data want ;
   set have1  (in=in1 rename=(abc=pdq) )
       have2  (in=in2 rename=(xyz=pdq) )
       have3  (in=in3 rename=(nom=pdq) )
       have4  (in=in4 rename=(bad=pdq) )
   ;
   indicator = sum(in1*1,in2*2,in3*3,in4*4);
run;

The IN= option creates a temporary data set that has a value of 1 when the current data record is from that data set, 0 otherwise.

The indicator uses the 0/1 information to create a variable with values from 1 to 4.

 

If this were my data I would likely have a Title that was something about "Patients at Risk" and only the first part of your current titles would go into the format.

View solution in original post

6 REPLIES 6
Reeza
Super User
How do you want those images combined? Have you tried using the TMPLOUT option in PROC SGPLOT to get your template code?
antor82
Obsidian | Level 7
1) I would like to combine them in a L2R2 layout

2) actually I haven’t tried the TMPLOUT option yet

Tks in advance

A
antor82
Obsidian | Level 7

Dear Reeza,

 

 

I got the template from TMPLOUT= option.

 

My question now is:

How could I join together 4 template codes from 4 different dataset files?

Reeza
Super User
You'll still have to combine the files as indicated by BallardW - that's an issue I hadn't caught in my original question. I'm wondering if ODS DOCUMENT wouldn't be easier? Just to clarify you don't want a PDF with a single page with all 4 graphs, you definitely want all as a PNG/JPEG file?
antor82
Obsidian | Level 7
I'm trying to combine these files, keeping only the variables of interests.
Yes, the final format should be png/jpeg.
ballardw
Super User

Most of the approaches to single image will rely on a single data set to allow the procedure to generate image.

 

Since your plots appear similar I would suspect one approach would be to

1)  get the same x y variable names in each set

2)  combine the data adding a variable to indicate which set each record comes from

3) create a custom format to display the text for the Title statement as the values of a format for the data set indicator variable

4) use SGPANEL with the combined data, use a PANELBY statement using the data set indicator variable with desired options,

   options would likely be Rows=2 Columns=2 ONEPANEL if you want a 2 by 2 layout.

5) use COLAXISTABLE instead of xaxistable

6) a COLAXIS statement that looks pretty similar to your XAXIS statement.

 

use the custom format for the dataset indicator variable. That should become the label for each section of the panel graph.

 

Combining and renaming the data is not that difficult. Below is a generic example:

data want ;
   set have1  (in=in1 rename=(abc=pdq) )
       have2  (in=in2 rename=(xyz=pdq) )
       have3  (in=in3 rename=(nom=pdq) )
       have4  (in=in4 rename=(bad=pdq) )
   ;
   indicator = sum(in1*1,in2*2,in3*3,in4*4);
run;

The IN= option creates a temporary data set that has a value of 1 when the current data record is from that data set, 0 otherwise.

The indicator uses the 0/1 information to create a variable with values from 1 to 4.

 

If this were my data I would likely have a Title that was something about "Patients at Risk" and only the first part of your current titles would go into the format.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1558 views
  • 3 likes
  • 3 in conversation