BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
A_Kh
Lapis Lazuli | Level 10

Hi Community, 

 

Regardless some suggestions in the sas community and specifications in sas documentation, I couldn't find a way to create images in EPS format using ODS Graphics. 
Calling Community Experts for help and guidance. I cannot provide data for this problem, but attaching my code and log. Hope someone could help me out. 

Thank you!

My Code:

ods _all_ close; 
ods graphics on; 
ods listing  /*image_dpi=600*/ gpath= "&mypath\EPS images";
	ods graphics / imagename="imagename" outputfmt=eps reset=index noborder;
	ods select survivalplot(persist);
	proc lifetest data=have method = km plots=survival(nocensor cb=hw  atrisk(outside(0.10)));
		time month*cnsr(1);
	 	strata actarm / order = internal ;
	run;
ods graphics off; 

log with ERROR:

NOTE: The LOGLOG transform is used to compute the confidence limits for
      the quartiles of the survivor distribution and the confidence limit
      for the survivor function. To suppress using this transform, specify
      CONFTYPE=LINEAR in the PROC LIFETEST statement.
NOTE: The graph in the LISTING destination will be rendered as an image
      due to the use of transparency.
ERROR: Unsupported image file format for output file.
ERROR: Unsupported image file format for output file.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE LIFETEST used (Total process time):
      real time           0.26 seconds
      cpu time            0.06 seconds
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Here are the steps:

-- Run ODS PATH SHOW; to check your paths for template reading and writing. The default will look something like the following:

Current ODS PATH list is: 

1. SASUSER.TEMPLAT(UPDATE) 
2. SASHELP.TMPLMST(READ)

This would cause your changes to be written to SASUSER.TEMPLAT, which is permanent storage. That would mean that every time you ran PROC LIFETEST, it would pick up your changes, which is probably not desirable. I would recommend running the following statement:

ods path (prepend)work.templat(update);

which will make your template write and read from template store live only for the life of your session.

-- Add ODS TRACE ON; to the top of your original program and re-run it. The log will tell you which template was used to produce the plot (let's pick stat.lifetest.graphics.productlimitsurvival for this example).

-- Using the template name, run the following code. The proc will put the source to the template in the log, starting with "define statgraph" and ending with an "end;"

 

proc template;
source stat.lifetest.graphics.productlimitsurvival;
run;

-- In a clean editor, create the following code block:

 

 

proc template;
< code from the log >
run;

-- In the code, look for all occurrences of the DATATRANSPARENCY option and remove them.

 

-- Submit the code. You should see it write to WORK.TEMPLATE.

-- Submit your original PROC LIFETEST code and see if you can generate an EPS file now.

 

Let me know how it goes 🙂

View solution in original post

9 REPLIES 9
A_Kh
Lapis Lazuli | Level 10

I could send matrixplot (from proc corr) into EPS file. Please see below. Why Survival plot cannot be sent into EPS, does it produce an image with different format? 

ods graphics on; 
ods _all_ close; 
ods listing  image_dpi=600 gpath= "&mypath\test";
ods graphics / imagename="classmatrix" outputfmt=eps reset=index noborder;
ods exclude all; 
ods select MatrixPlot; 
proc corr data =sashelp.class plots=matrix(histogram);
	var age height weight;
run;

 Result:
Capture.PNG
@DanH_sas looping you in for awareness, as I think this question should be solved in a new thread

DanH_sas
SAS Super FREQ

There is the reason the survival plot failed to produce an EPS file is because of this note in the log:

 

NOTE: The graph in the LISTING destination will be rendered as an image
      due to the use of transparency.

Once it got turned into an image, it could not be put into a vector-based EPS file. It is possible for you to modify the graph template used by PROC LIFETEST to remove the DATATRANSPARENCY options in the definitions, as they might not be needed for your case. Let me know if you want to pursue that approach, and I can describe how to make that change. 

A_Kh
Lapis Lazuli | Level 10

I like this approach and would like to know how to modify transparency in graphics template

DanH_sas
SAS Super FREQ

Here are the steps:

-- Run ODS PATH SHOW; to check your paths for template reading and writing. The default will look something like the following:

Current ODS PATH list is: 

1. SASUSER.TEMPLAT(UPDATE) 
2. SASHELP.TMPLMST(READ)

This would cause your changes to be written to SASUSER.TEMPLAT, which is permanent storage. That would mean that every time you ran PROC LIFETEST, it would pick up your changes, which is probably not desirable. I would recommend running the following statement:

ods path (prepend)work.templat(update);

which will make your template write and read from template store live only for the life of your session.

-- Add ODS TRACE ON; to the top of your original program and re-run it. The log will tell you which template was used to produce the plot (let's pick stat.lifetest.graphics.productlimitsurvival for this example).

-- Using the template name, run the following code. The proc will put the source to the template in the log, starting with "define statgraph" and ending with an "end;"

 

proc template;
source stat.lifetest.graphics.productlimitsurvival;
run;

-- In a clean editor, create the following code block:

 

 

proc template;
< code from the log >
run;

-- In the code, look for all occurrences of the DATATRANSPARENCY option and remove them.

 

-- Submit the code. You should see it write to WORK.TEMPLATE.

-- Submit your original PROC LIFETEST code and see if you can generate an EPS file now.

 

Let me know how it goes 🙂

A_Kh
Lapis Lazuli | Level 10

Thank you so much, @DanH_sas!
Your guidance was so useful, I've learnt something new and found related documentation as well. 
Your codes created EPS file without transparency of shaded areas.. Please see below.
EPS file.

survivalplot without transparency.PNG
Previously, this plot, with transparency, looked like as below.
PNG file. (Same for EPSI file).
survivalplot with transparency.PNG

I've even tried changing original transparency levels (datatransparency=.55)  in the PROC TEMPLATE step, but it didn't produce EPS file causing the same error again. Looks like transparency needs to be completely off for EPS files. 



DanH_sas
SAS Super FREQ

For your purposes, you could change the BANDPLOTs from being FILLed to being OUTLINEd using the DISPLAY option. That way, all of the information can be seen.

A_Kh
Lapis Lazuli | Level 10

Added DISPLAY=(OUTLINE) option after each BANDPLOT and get this result. 

proc template;
define statgraph Stat.Lifetest.Graphics.ProductLimitSurvival2;
dynamic NStrata xName plotAtRisk plotCensored plotCL plotHW plotEP labelCL labelHW
labelEP maxTime xtickVals xtickValFitPol rowWeights method StratumID classAtRisk
plotTest GroupName Transparency SecondTitle TestName pValue _byline_ _bytitle_ _byfootnote_;
BeginGraph;
if (NSTRATA=1)
if (EXISTS(STRATUMID))
entrytitle METHOD " Survival Estimate" " for " STRATUMID;
else entrytitle METHOD " Survival Estimate";
endif;
entrytitle "With Number of Subjects at Risk" / textattrs=GRAPHVALUETEXT;
layout lattice / rows=2 rowweights=ROWWEIGHTS columndatarange=union rowgutter
=10;
cell;
layout overlay / xaxisopts=(shortlabel=XNAME offsetmin=.05 linearopts=(
viewmax=MAXTIME tickvaluelist=XTICKVALS tickvaluefitpolicy=
XTICKVALFITPOL)) yaxisopts=(label="Survival Probability" shortlabel=
"Survival" linearopts=(viewmin=0 viewmax=1 tickvaluelist=(0 .2 .4 .6
.8 1.0)));
if (PLOTHW=1 AND PLOTEP=0)
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME / displayTail
=false modelname="Survival" fillattrs=GRAPHCONFIDENCE name=
"HW" legendlabel=LABELHW display=(outline);
endif;
if (PLOTHW=0 AND PLOTEP=1)
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME / displayTail
=false modelname="Survival" fillattrs=GRAPHCONFIDENCE name=
"EP" legendlabel=LABELEP display=(outline);
endif;
if (PLOTHW=1 AND PLOTEP=1)
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME / displayTail
=false modelname="Survival" fillattrs=GRAPHDATA1
name="HW" legendlabel=LABELHW display=(outline);
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME / displayTail
=false modelname="Survival" fillattrs=GRAPHDATA2
name="EP" legendlabel=LABELEP display=(outline);
endif;
if (PLOTCL=1)
if (PLOTHW=1 OR PLOTEP=1)
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME /
displayTail=false modelname="Survival" display=(outline)
outlineattrs=GRAPHPREDICTIONLIMITS name="CL" legendlabel=
LABELCL display=(outline);
else
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME /
displayTail=false modelname="Survival" fillattrs=
GRAPHCONFIDENCE name="CL" legendlabel=LABELCL display=(outline);
endif;
endif;
stepplot y=SURVIVAL x=TIME / name="Survival" rolename=(_tip1=ATRISK
_tip2=EVENT) tiplabel=(_tip1="Number at Risk" _tip2=
"Observed Events") tip=(x y _tip1 _tip2) legendlabel="Survival";
if (PLOTCENSORED=1)
scatterplot y=CENSORED x=TIME / markerattrs=(symbol=plus)
tiplabel=(y="Survival Probability") name="Censored"
legendlabel="Censored";
endif;
if (PLOTCL=1 OR PLOTHW=1 OR PLOTEP=1)
discretelegend "Censored" "CL" "HW" "EP" / location=outside
halign=center;
else
if (PLOTCENSORED=1)
discretelegend "Censored" / location=inside autoalign=(
topright bottomleft);
endif;
endif;
endlayout;
endcell;
cell;
layout overlay / walldisplay=none xaxisopts=(display=none);
axistable x=TATRISK value=ATRISK / display=(label) valueattrs=(size=
7pt);
endlayout;
endcell;
endlayout;
else
entrytitle METHOD " Survival Estimates";
if (EXISTS(SECONDTITLE))
entrytitle SECONDTITLE / textattrs=GRAPHVALUETEXT;
endif;
layout lattice / rows=2 rowweights=ROWWEIGHTS columndatarange=union rowgutter
=10;
cell;
layout overlay / xaxisopts=(shortlabel=XNAME offsetmin=.05 linearopts=(
viewmax=MAXTIME tickvaluelist=XTICKVALS tickvaluefitpolicy=
XTICKVALFITPOL)) yaxisopts=(label="Survival Probability" shortlabel=
"Survival" linearopts=(viewmin=0 viewmax=1 tickvaluelist=(0 .2 .4 .6
.8 1.0)));
if (PLOTHW=1)
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME / displayTail
=false group=STRATUM index=STRATUMNUM modelname="Survival"
display=(outline);
endif;
if (PLOTEP=1)
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME / displayTail
=false group=STRATUM index=STRATUMNUM modelname="Survival"
display=(outline);
endif;
if (PLOTCL=1)
if (PLOTHW=1 OR PLOTEP=1)
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME /
displayTail=false group=STRATUM index=STRATUMNUM modelname=
"Survival" display=(outline) outlineattrs=(pattern=
ShortDash) display=(outline);
else
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME /
displayTail=false group=STRATUM index=STRATUMNUM modelname=
"Survival" display=(outline);
endif;
endif;
stepplot y=SURVIVAL x=TIME / group=STRATUM index=STRATUMNUM name=
"Survival" rolename=(_tip1=ATRISK _tip2=EVENT) tiplabel=(_tip1=
"Number at Risk" _tip2="Observed Events") tip=(x y _tip1 _tip2);
if (PLOTCENSORED=1)
scatterplot y=CENSORED x=TIME / group=STRATUM index=STRATUMNUM
tiplabel=(y="Survival Probability") markerattrs=(symbol=plus);
endif;
DiscreteLegend "Survival" / title=GROUPNAME location=outside;
if (PLOTCENSORED=1)
if (PLOTTEST=1)
layout gridded / rows=2 autoalign=(TOPRIGHT BOTTOMLEFT TOP
BOTTOM) border=true BackgroundColor=GraphWalls:Color Opaque
=true;
entry "+ Censored";
if (PVALUE < .0001)
entry TESTNAME " p " eval (PUT(PVALUE, PVALUE6.4));
else
entry TESTNAME " p=" eval (PUT(PVALUE, PVALUE6.4));
endif;
endlayout;
else
layout gridded / rows=1 autoalign=(TOPRIGHT BOTTOMLEFT TOP
BOTTOM) border=true BackgroundColor=GraphWalls:Color Opaque
=true;
entry "+ Censored";
endlayout;
endif;
else
if (PLOTTEST=1)
layout gridded / rows=1 autoalign=(TOPRIGHT BOTTOMLEFT TOP
BOTTOM) border=true BackgroundColor=GraphWalls:Color Opaque
=true;
if (PVALUE < .0001)
entry TESTNAME " p " eval (PUT(PVALUE, PVALUE6.4));
else
entry TESTNAME " p=" eval (PUT(PVALUE, PVALUE6.4));
endif;
endlayout;
endif;
endif;
endlayout;
endcell;
cell;
layout overlay / walldisplay=none xaxisopts=(display=none);
axistable x=TATRISK value=ATRISK / display=(label) valueattrs=(size=
7pt) class=CLASSATRISK colorgroup=CLASSATRISK;
endlayout;
endcell;
endlayout;
endif;
if (_BYTITLE_)
entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT;
else
if (_BYFOOTNOTE_)
entryfootnote halign=left _BYLINE_;
endif;
endif;
EndGraph;
end;
run;

survivalplot without transparency outlined.PNG

 

DanH_sas
SAS Super FREQ

That is the expected output. Now, if you want, you can also tweak the line attributes to improve the display. For example, set LINEATTRS=(thickness=3) on the STEPPLOTs to help them stand out from the bands. 

A_Kh
Lapis Lazuli | Level 10

I see, it bolded survival lines. Thank you again!
I really appreciate you taking time to look into my question.  For me, the problem is solved at this point, I've EPS file which I needed to create and should be able to modify plot attributes as needed. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 9 replies
  • 996 views
  • 2 likes
  • 2 in conversation