BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dig8d0
Calcite | Level 5

I have read SAS threads on exporting multiple graphs which use the same predictor and response variables, but I need to export multiple graphs into a single JPG file (or EPS or TIF) when a different predictor variable is used each time. In addition, there is a group variable for some but not all graphs.

 

Here is the code to output to a Word file (not allowed by journal to which I am submitting):

 

 
 
/*muscle-liver figure without interaction*/
 
proc glm data=som.pittonly ;
class  EEFEMALE (ref="1: Yes")  prediabetes;
options fmtsearch=(SOM.formats);
   model log_MRMLIVFAT = CRPERCSC D1AGE EEFEMALE ACTMMVPAM prediabetes/ solution  clparm tolerance;
   where  ACTMMVPAM >1 and CRPERCSC>0.00001;
   estimate 'CRPERCSC' CRPERCSC 0.0680996; 
store contcont;
output out=outpred p=p lclm=lower uclm=upper;
run; 
quit;
 
DATA INPLOTDATA;
 
ACTMMVPAM=179.4505; 
d1age=75; 
EEFEMALE=0;
prediabetes=0;
 
do CRPERCSC = .10 to .50 by .1;
OUTPUT;
END;
RUN;
 
PROC PLM RESTORE=CONTCONT;
SCORE DATA=INPLOTDATA OUT=PLOTDATAnoint PRED=FIT UCLM=U LCLM=L ;
RUN;
 
proc sort data = PLOTDATAnoint; 
by  CRPERCSC ; 
run;
 
 
 
 
 
/*muscle-liver with WC interaction*/
 
proc glm data=som.pittonly ;
class  EEFEMALE (ref="1: Yes") high_WC prediabetes;
options fmtsearch=(SOM.formats);
   model log_MRMLIVFAT = CRPERCSC|high_WC D1AGE EEFEMALE ACTMMVPAM prediabetes/ solution  clparm tolerance;
   where high_wc ne . and ACTMMVPAM >1 and CRPERCSC>0.00001;
store contcont;
output out=outpred p=p lclm=lower uclm=upper;
run; 
quit;
 
 
DATA INPLOTDATA;
 
ACTMMVPAM=179.4505; 
d1age=75; 
EEFEMALE=0;
prediabetes=0;
 
do CRPERCSC = 0.1 to 0.5 by 0.1;
DO high_WC=0, 1;
OUTPUT;
END;
end;
RUN;
 
PROC PLM RESTORE=CONTCONT;
SCORE DATA=INPLOTDATA OUT=PLOTDATA PRED=FIT UCLM=U LCLM=L ;
RUN;
 
proc sort data = PLOTDATA; 
by  CRPERCSC high_WC; 
run;
 
proc format;
value high_wc
0='Normal'
1='High';
run;
 
 
 
 
/*MFI adjusted figure NO INTERACTION*/
 
proc glm data= som.pittonly;
class  EEFEMALE (ref="1: Yes") prediabetes;
options fmtsearch=(SOM.formats);
   model log_MRMLIVFAT = MRMATHMFI D1AGE EEFEMALE ACTMMVPAM prediabetes/ solution  clparm tolerance;
store contcont;
run; 
 
DATA INPLOTDATA;
 
ACTMMVPAM=179.4505; 
d1age=75; 
EEFEMALE=0;
prediabetes=0;
 
do MRMATHMFI = 0.0 to 0.16 by 0.02;
OUTPUT;
END;
RUN;
 
PROC PLM RESTORE=CONTCONT;
SCORE DATA=INPLOTDATA OUT=PLOTDATA_MFI PRED=FIT UCLM=U LCLM=L ;
RUN;
 
proc sort data = PLOTDATA_MFI; 
by  MRMATHMFI ; 
run;
 
 
ODS _ALL_ CLOSE; 
ods graphics on /noborder /*width= 410 px height=300 px*/ width=4in height=3in imagefmt=tiff;
options nocenter nonumber nodate orientation=landscape;
ods word columns=2 file = "C:\Users\Figure 1.docx" STARTPAGE=no;
 
/*MUSCLE-LIVER NO INTERACTION*/
 
proc sgplot data=PLOTDATAnoint noborder noautolegend ; 
format CRPERCSC percent9.4;
band x=CRPERCSC lower=l upper=u  /  transparency=0.3 ;
series x=CRPERCSC y=fit /   markers markerattrs=(symbol="circlefilled" size=5)  lineattrs=(pattern=1 color=black); /*lineattrs=(thickness=2)*/ 
series x=CRPERCSC y=u / lineattrs=(pattern=1 color=black);
series x=CRPERCSC y=l / lineattrs=(pattern=1 color=black); 
xaxis label = "Muscle Mass (%)" values = (.10 to .50 by .10) LABELATTRS=(size=12pt family="Arial")  valueattrs=(size=12pt family="Arial"); 
yaxis label = "Log Liver Fat (%)" values = (-5.0 to 0 by 0.50) LABELATTRS=(size=12pt family="Arial")  valueattrs=(size=12pt family="Arial"); 
 INSET "P=0.82" "Per-SD Adjusted Beta 95%CI:" "-0.87 (-8.1, 6.9)" /  TEXTATTRS = (SIZE=12 family="Arial");
run;
 
/*MFI-LIVER NO INTERACTION*/
 
proc sgplot data=PLOTDATA_MFI noborder noautolegend ; 
format MRMATHMFI percent9.4;
band x=MRMATHMFI lower=l upper=u  /  transparency=0.3 ;
series x=MRMATHMFI y=fit /   markers markerattrs=(symbol="circlefilled" size=5)  lineattrs=(pattern=1 color=black); /*lineattrs=(thickness=2)*/ 
series x=MRMATHMFI y=u / lineattrs=(pattern=1 color=black);
series x=MRMATHMFI y=l / lineattrs=(pattern=1 color=black); 
xaxis label = "Mean Anterior Thigh Muscle Fat Infiltration (%)" values = (0.0 to 0.16 by 0.02) LABELATTRS=(size=12pt family="Arial")  valueattrs=(size=11pt family="Arial"); 
yaxis label = "Log Liver Fat (%)" values = (-5.0 to 0 by 0.50) LABELATTRS=(size=12pt family="Arial")  valueattrs=(size=12pt family="Arial"); 
 INSET "P=0.0003" "Per-SD Adjusted Beta 95%CI:" "15.2 (6.8, 24.3)" /  TEXTATTRS = (SIZE=12 family="Arial");
run;
 
 
proc sort data = outpred; 
by  high_WC CRPERCSC ; 
run;
 
 
/*MUSCLE-LIVER WITH INTERACTION*/
 
 
proc sgplot data=PLOTDATA noborder  ; 
format high_WC high_WC. CRPERCSC percent9.4;
label high_WC = "Waist circumference";
band x=CRPERCSC lower=l upper=u   /  group=high_WC transparency=0.3;
styleattrs   datacolors=(blue orange );
series x=CRPERCSC y=fit / group=high_WC  markers markerattrs=(symbol="circlefilled" size=5 )  lineattrs=(pattern=1 color=black); /*lineattrs=(thickness=2)*/ 
series x=CRPERCSC y=u / group=high_WC lineattrs=(pattern=1 color=black);
series x=CRPERCSC y=l / group=high_WC lineattrs=(pattern=1 color=black); 
xaxis label = "Muscle Mass (%)" values = (.1 to .5 by .1) LABELATTRS=(size=12pt family="Arial")  valueattrs=(size=12pt family="Arial"); 
yaxis label = "Log Liver Fat (%)" values = (-5.0 to 0 by 0.50) LABELATTRS=(size=12pt family="Arial")  valueattrs=(size=12pt family="Arial"); 
 INSET ("(*ESC*){UNICODE P}" = "Interaction P=0.001" ) /  TEXTATTRS = (SIZE=12 family="Arial");
run;
 
 
ods word close;

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Sorry, I was referring to this blog post: https://blogs.sas.com/content/graphicallyspeaking/2022/09/10/complex-layouts-using-the-sg-procedures...

 

Instead of using PNG, you should be able to use JPEG for your output. Try changing the PRINTER from PNG300 to JPEG (and change the extension on the output file). Let me know if that works for you.

View solution in original post

11 REPLIES 11
sbxkoenk
SAS Super FREQ

Hello @dig8d0 ,

 

does this help?

multiple graph in a single output - SAS University Edition
Posted 07-10-2019 03:14 PM 
https://communities.sas.com/t5/New-SAS-User/multiple-graph-in-a-single-output-SAS-University-Edition...

 

Maybe @PaulV can help you out?

 

Koen

dig8d0
Calcite | Level 5

Hi Koen,

 

I think this could be helpful although if I'm not mistaken, PROC SGPANEL does not have many formatting options, which was why I was hoping to use SGPLOT. Would I need to use a template for formatting? I have not tried using templates before so any relevant guidance would be appreciated.

 

Thanks!

Daria

dig8d0
Calcite | Level 5

Thanks, Paige!

 

This looks promising although would this approach allow for outputting the figure panels as one png, tif, or eps file? An issue I'm having is that I can't submit figures in PDF or Word format.

 

Thanks!

Daria

DanH_sas
SAS Super FREQ

The technique in the blog post should work for jpeg as well.

dig8d0
Calcite | Level 5

In the post (Solved: ODS LAYOUT ABSOLUTE with a BY statement in PROC SGPLOT - SAS Support Communities), it looks like the solution relies on outputting to PDF using ODS PDF. I don't think such an option exists to output to JPG. Is there another way to output as JPG using the PROC DOCUMENT solution?

 

Thanks!

Daria

DanH_sas
SAS Super FREQ

Sorry, I was referring to this blog post: https://blogs.sas.com/content/graphicallyspeaking/2022/09/10/complex-layouts-using-the-sg-procedures...

 

Instead of using PNG, you should be able to use JPEG for your output. Try changing the PRINTER from PNG300 to JPEG (and change the extension on the output file). Let me know if that works for you.

dig8d0
Calcite | Level 5

I am getting the following error in the log:

 

ods printer printer=jpeg file="C:\Figures and Supplemental\Figure1.jpeg" style=normalprinter;
ERROR: Unable to set printer path per request. This is usually because the requested printer (JPEG) is unknown.

 

Any workarounds? I tried setting as jpg instead and get the same error.

 

Thanks!

Daria

dig8d0
Calcite | Level 5

Update:

 

This solution worked when changing file extension to .tiff! I just had to increase the paper size to fit all 3 panels (and specified rows=2).

 

Thanks so much!

Daria

DanH_sas
SAS Super FREQ

I'm glad you got what you needed 😀. I am curious why JPEG did not work. I looked in the device catalog, and there is both a JPEG and JPEG300 device. Just for grins, could you try JPEG300 and see if it works for you?

dig8d0
Calcite | Level 5

I get the same type of error when setting printer to JPEG300:

 

ods printer printer=JPEG300 file="C:\Users\Figures and Supplemental\Figure2.jpeg" style=normalprinter;

 

ERROR: Unable to set printer path per request. This is usually because the requested printer (JPEG300) is unknown.

 

My SAS license is due for an update; I doubt that would have anything to do with it. Happy to try other solutions if it helps!

 

Daria

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 2715 views
  • 0 likes
  • 4 in conversation