Hi,
I need to save my Kaplan-Meier curves in a format other that will be more easily editable for a journal. Right now, SAS is only allowing me to save the images as .png or .bmp files. Is there a way I can just add a outputfmt= statement to my code to output my curves as .ai, .eps, or .pdf files? Here is the code I am using below. Thank you in advance!
data _null_;
%let url = //support.sas.com/documentation/onlinedoc/stat/ex_code/142;
infile "http:&url/templft.html" device=url;
file 'macros.tmp';
retain pre 0;
input;
_infile_ = tranwrd(_infile_, '&', '&');
_infile_ = tranwrd(_infile_, '<' , '<');
if index(_infile_, '</pre>') then pre = 0;
if pre then put _infile_;
if index(_infile_, '<pre>') then pre = 1;
run;
%inc 'macros.tmp' / nosource;
* Modify the template;
%ProvideSurvivalMacros
%let TitleText0 = "Kaplan-Meier Plot: Probability of death, stratified by CD4 count at time of HIV diagnosis";
%let yOptions = label="Survival Probability"
linearopts=(viewmin=0.7 viewmax=1 tickvaluelist=(0.7 0.8 0.9 1.0));
%let xOptions = label="Time (days since release)" ;
%let GraphOpts = DataContrastColors=(green red blue)
DataColors=(green red blue);
/*%let TitleText1 = &titletext0 "CD4 count at diagnosis " STRATUMID;*/
%CompileSurvivalTemplates
*KM stratified by AIDS STAGE**************************************************************;
proc format ;
invalue CD4_atdiagnosiscat '>=500 cells/µL' = 1 '200-499 cells/µL' = 2 '<200 cells/µL' = 3;
value CD4_atdiagnosisfmt 1 = '>=500 cells/µL' 2 = '200-499 cells/µL' 3 = '<200 cells/µL';
run;
data tempCD4(drop=g);
set CLEAN.databasesurv3(rename=(CD4_atdiagnosis=g));
CD4_atdiagnosis = input(g, CD4_atdiagnosiscat.);
run;
* Analysis;
ods graphics on;
proc lifetest data=work.tempCD4 method=km atrisk
plots=(S(test nocensor atrisk(maxlen=16 outside(0.12))=0 to 3000 by 500) /*method=km MAXTIME= 3000 intervals=(0 to 3000 by 500)*/);
time time*EVENT_ANYDEATH(0);
strata CD4_atdiagnosis / order=internal adjust=sidak test=logrank ;
label CD4_atdiagnosis = "CD4 count at diagnosis";
format CD4_atdiagnosis CD4_atdiagnosisfmt.;
run;
ods graphics off;
don't journals typically demand tiff?
Here is what we were instructed: "For any statistical images you should provide editable vector files (ie, the original artwork generated by the statistical package used to make the image); our preferred formats for these files are .ai, .eps, or .pdf." Do you think a .png file would be acceptable based on these guidelines?
I was able to figure out how to generate a pdf file using the bolded statement. However, when looking at the PDF files produced, for some reason SAS is making 2 of the 3 the K-M lines formatted as dotted instead of simple solid lines. This is not how they show up in SAS, which is confusing me and I am not sure how to tweak the code to fix this.
ods graphics on / OUTPUTFMT=pdf imagename="K-M Curve CD4";
ods listing gpath="J:\Kelsey data created 03.16.2016\Kelsey's mortality folder";
proc lifetest data=work.tempCD4 method=km atrisk
plots=(S(test nocensor atrisk(maxlen=16 outside(0.12))=0 to 3000 by 500) /*method=km MAXTIME= 3000 intervals=(0 to 3000 by 500)*/);
time time*EVENT_ANYDEATH(0);
strata CD4_atdiagnosis / order=internal adjust=sidak test=logrank ;
label CD4_atdiagnosis = "CD4 count at diagnosis";
format CD4_atdiagnosis CD4_atdiagnosisfmt.;
run;
ods graphics off;
ok, i've been there before. I think i created tiff and then used gimp to convert to eps or pdf. Install gimp 2 then search google 'convert tiff to eps using gimp', something like that
For PDF you can also use ODS PDF.
I put this code together using outputfmt (also tried imagefmt) but unfortunately PDF is not supported by the destination I am trying to save it to:
ods graphics on / OUTPUTFMT=pdf imagename="K-M Curve CD4";
ods listing gpath="C:\Users\Kelsey\Desktop\SURVIVAL CURVES - PDF ATTEMPTS" ;
proc lifetest data=work.tempCD4 method=km atrisk
plots=(S(test nocensor atrisk (maxlen=16 outside(0.12))=0 to 3000 by 500) /*method=km MAXTIME= 3000 intervals=(0 to 3000 by 500)*/);
time time*EVENT_ANYDEATH(0);
strata CD4_atdiagnosis / order=internal adjust=sidak test=logrank ;
label CD4_atdiagnosis = "CD4 count at diagnosis";
format CD4_atdiagnosis CD4_atdiagnosisfmt.;
run;
ods graphics off;
Any additional suggestions for how to get around this? I find it hard to believe that there is no standardized way of saving a survival curve as a PDF directly from SAS.
Thank you in advance.
Hi:
As @Reeza already suggested, you CAN save ALL your output in PDF format by using ODS PDF. For that you don't need imagefmt or outputfmt options.
Cynthia
You might also want to tweak the resolution for publication -- see tips from @Jay54 on this topic.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.