DATA Step, Macro, Functions and more

How do I save a Kaplan-Meier curve as .ai, .eps, or .pdf file?

Reply
Contributor
Posts: 55

How do I save a Kaplan-Meier curve as .ai, .eps, or .pdf file?

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_, '&lt;' , '<');

   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;

 

Regular Contributor
Posts: 164

Re: How do I save a Kaplan-Meier curve as .ai, .eps, or .pdf file?

don't journals typically demand tiff?

--------------
blog: papersandprograms.com
Contributor
Posts: 55

Re: How do I save a Kaplan-Meier curve as .ai, .eps, or .pdf file?

Posted in reply to PaulBrownPhD

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;

Regular Contributor
Posts: 164

Re: How do I save a Kaplan-Meier curve as .ai, .eps, or .pdf file?

[ Edited ]

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

 

edit: http://gimpchat.com/viewtopic.php?f=8&t=8245

--------------
blog: papersandprograms.com
Super User
Posts: 23,773

Re: How do I save a Kaplan-Meier curve as .ai, .eps, or .pdf file?

For PDF you can also use ODS PDF. 

 

SAS Super FREQ
Posts: 9,371

Re: How do I save a Kaplan-Meier curve as .ai, .eps, or .pdf file?

Hi, the ODS GRAPHICS statement supports an imagefmt= option. But, the value has to be supported by the destination you're using. I suggest you look at the documentation for the ODS GRAPHICS statement and the imagefmt option.

Cynthia
Contributor
Posts: 55

Re: How do I save a Kaplan-Meier curve as .ai, .eps, or .pdf file?

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.

SAS Super FREQ
Posts: 9,371

Re: How do I save a Kaplan-Meier curve as .ai, .eps, or .pdf file?

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

Community Manager
Posts: 3,441

Re: How do I save a Kaplan-Meier curve as .ai, .eps, or .pdf file?

Posted in reply to Cynthia_sas

You might also want to tweak the resolution for publication -- see tips from @Sanjay_SAS on this topic.

Ask a Question
Discussion stats
  • 8 replies
  • 122 views
  • 0 likes
  • 5 in conversation