Hi Folks:
I'm trying to compare the distribution of survival time across A, B, C and D groupS of populations. However, x-axis range of my kernel density plot doesn't match (it even took negative value) to the range of underlying data. Proc means returns min=0 and max 4015. Am I missing to specify any options in the proc sgplot to match x-axis to the underlying data? How to tie my x-axis to the data?
Any hints appreciated.
Thanks in advance.
proc sgplot data = MYDATA;
title "SURVIVAL TIME DISTRIBUTION";
yaxis label = "Percent" offsetmax=0 values=(0 to 8 by 0.5);
xaxis label = "What is X axis?" grid;
styleattrs DATACONTRASTCOLORS=(BLUE green PURPLE red);
density DUR_GOLD / scale=percent type = kernel legendlabel = "A" ;
density DUR_RAND / scale=percent type = kernel legendlabel = "B" ;
density DUR_MID / scale=percent type = kernel legendlabel = "C" ;
density SURV_DAYS / scale=percent type = kernel legendlabel = "D" ;
keylegend / location=OUTSIDE position=top;
run;
proc means data=MYDATA maxdec=1 max min;
var A B C D;
run;
Density plots are based on an estimated distribution as requested and as such the distribution indicated by your data will often have values outside the range of your data. The display will tend to cut off at a point where no more useful information is displayed, i.e. all of the Y values are so close to 0 that you can't tell the difference.
A normal distribution always has a domain (x values) of plus or minus infinity. But typically when you get to X plus/minus 4 standard deviations there isn't much detectible difference in the Y values.
If you really don't want to see the curve past your limits provide a VALUES clause to the XAXIS statement.
tHANKS @ballardw
Specifying limits results in following plot.
proc sgplot data = mydata; /*N=12,061*/
title "SURVIVAL TIME DISTRIBUTION";
yaxis label = "Percent" offsetmax=0 values=(0 to 8 by 0.5);
xaxis label = "Survival Time in Days" grid offsetmax=0 values=(0 to 4500 by 100);
styleattrs DATACONTRASTCOLORS=(BLUE green PURPLE red);
density DUR_GOLD / scale=percent type = kernel legendlabel = "A" ;
density DUR_RAND / scale=percent type = kernel legendlabel = "B" ;
density DUR_MID / scale=percent type = kernel legendlabel = "C" ;
density SURV_DAYS / scale=percent type = kernel legendlabel = "D" ;
keylegend / location=OUTSIDE position=top;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.