BookmarkSubscribeRSS Feed
PriyeshSura17
Calcite | Level 5

While plotting Survival plot in SAS 9.3 (Windows Platform), I want to use GTL or PROC SGPLOT. I am able to get the things done using annotation and PROC GPLOT, but need to make a template I can use flexibly as needed. Hence, I've used proc template to create a template. I am stuck at one point and require a guidance.

While using PROC GPLOT, I use annotation of desired symbol, "|" as follows:

symbol3 interpol=none    v =I       line=2    HEIGHT=2 font=bold;

I have tried searching a lot but was unable to find the replacement of this statement in proc template (GTL). I would like to have "|" as symbol for censored observation in survival plot. Also, the same symbol should be displayed in the legend as "| | | Censored Observations".

I've tried using following template, with no luck!

 

proc template;
define statgraph kmplot;
    nmvar _ymin _ymax _yinc _xmin _xmax _xinc;
    begingraph /designwidth=9.8in  designheight=4.8in border=false ;
        discreteattrmap name="treatment" / ignorecase=true;
            value "1" / lineattrs=(pattern=1);
            value "2" / lineattrs=(pattern=4); 
            value "3" / lineattrs=(pattern=2);    
        enddiscreteattrmap;
        discreteattrvar attrvar=treatmarkers var=Stratum attrmap="treatment";
        legendItem type=line name="line1" / lineattrs=(pattern=1) label="Placebo" ;
        legendItem type=line name="line2" / lineattrs=(pattern=4) label="TRTA" ;
        legendItem type=line name="line3" / lineattrs=(pattern=2) label="TRTB" ;
     legendItem type=marker name="censormkr" / markerattrs=(symbol=plus Weight=bold) label="Censored Observations" ;
        layout overlay / yaxisopts=(linearopts=(viewmin=_ymin viewmax=_ymax tickvaluesequence=(start=_ymin end=_ymax increment=_yinc))label = "Log Negative Log SDF" )
           xaxisopts=(linearopts=(viewmin=_xmin viewmax=_xmax tickvaluesequence=(start=_xmin end=_xmax increment=_xinc)) label="Log of Time (Days)")
                       walldisplay=all;
           stepplot x=time y=survival / group=treatmarkers lineattrs=(color=black) name="trtlgnd";
            scatterplot x=time y=survival / group=Stratum  /*markerchar=flag*/ markerattrs=(symbol=plus Weight=bold color=black) name="censored";
            referenceline y=.5; 
           *mergedlegend 'trtlgnd' 'censored';
            discretelegend "line1" "line2" "line3" "censormkr"/ valueattrs=(size=10pt) autoitemsize=true location=inside across=1 autoalign=(topright);
        endlayout;
   endgraph;
end;
run;

I've also tried to use "markerchar=flag" option by creating a flag variable containing desired symbol, by which I do get the Symbol in the plot (without any flexibility of having the symbol as bold), but no luck in getting the symbol in the legend as desired.

Please let me know how to get '|' dynamically, both in the plot and n the legend as well. Let me know if any further details from my end is required.

Thanks in Advance!

1 REPLY 1
djrisks
Barite | Level 11

Hello, please try the code below. All I basically done was use the markercharacter option to place the pipe symbol on the survivalplot, and then use type=text in legend item to place the pipe symbol in the legend.

 

I don't know if you used the survivalplot dataset before, but if you did, you may have been plotting the survival variable instead of the censored variable, and that may be why the pipe symbol was not being displayed as the censored observation.

 

ods output survivalplot = survivalplot;
proc lifetest data=sashelp.BMT plots=survival(atrisk=0 to 2500 by 500);
   time T * Status(0);
   strata Group / test=logrank adjust=sidak;
run;

data surv2;
  set survivalplot;
  treatmarkers = strip(put(StratumNum, best.));
  if censored ne . then censored2 = "|";
run;


proc template;
define statgraph kmplot;
    nmvar _ymin _ymax _yinc _xmin _xmax _xinc;
    begingraph /designwidth=9.8in  designheight=4.8in border=false ;
        discreteattrmap name="treatment" / ignorecase=true;
            value "1" / lineattrs=(pattern=1);
            value "2" / lineattrs=(pattern=4); 
            value "3" / lineattrs=(pattern=2);    
        enddiscreteattrmap;
        discreteattrvar attrvar=treatmarkers var=Stratum attrmap="treatment";
        legendItem type=line name="line1" / lineattrs=(pattern=1) label="Placebo" ;
        legendItem type=line name="line2" / lineattrs=(pattern=4) label="TRTA" ;
        legendItem type=line name="line3" / lineattrs=(pattern=2) label="TRTB" ;
        legendItem type=/*marker*/text name="censormkr" / text="|" /*markerattrs=(symbol=plus Weight=bold)*/ label="Censored Observations" ;
        layout overlay / yaxisopts=(linearopts=(viewmin=_ymin viewmax=_ymax tickvaluesequence=(start=_ymin end=_ymax increment=_yinc))label = "Log Negative Log SDF" )
           xaxisopts=(linearopts=(viewmin=_xmin viewmax=_xmax tickvaluesequence=(start=_xmin end=_xmax increment=_xinc)) label="Log of Time (Days)")
                       walldisplay=all;
           stepplot x=time y=survival / group=treatmarkers lineattrs=(color=black) name="trtlgnd";
            scatterplot x=time y=censored / group=Stratum  markercharacter=censored2 markercharacterattrs=(size=12 color=black weight=bold) /*markerattrs=(symbol=plus Weight=bold color=black)*/ name="censored";
            referenceline y=.5; 
           *mergedlegend 'trtlgnd' 'censored';
            discretelegend "line1" "line2" "line3" "censormkr"/ valueattrs=(size=10pt) autoitemsize=true location=inside across=1 autoalign=(topright);
        endlayout;
   endgraph;
end;
run;


proc sgrender data = surv2 template = kmplot;
run;

Please let me know if you have any questions.


Survival_with_pipe.png

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1 reply
  • 1391 views
  • 0 likes
  • 2 in conversation