Data visualization with SAS programming

pipe (|) symbol in the survival plot in SAS 9.3(Windows)

Reply
Regular Learner
Posts: 1

pipe (|) symbol in the survival plot in SAS 9.3(Windows)

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!

Super Contributor
Posts: 252

Re: pipe (|) symbol in the survival plot in SAS 9.3(Windows)

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.

Attachment
Ask a Question
Discussion stats
  • 1 reply
  • 272 views
  • 0 likes
  • 2 in conversation