I want to create a graph with a fixed x-axis range using the SGPLOT command. Specifically, I want the x-axis to range from -100 to 100 by 10. However, when I ran the code, the x-axis displayed a range of -25 to -75 by 25 instead.
Here is my code:
proc sgplot data=test5aT nowall noborder nocycleattrs dattrmap=attrmap noautolegend ;
title 'A';
format text $txt.;
styleattrs axisextent=data ;
highlow y=obsid low=low high=high/lineattrs=(thickness=.05);
scatter y=obsid x=percent / markerattrs=(symbol=circle size=10);
refline 1 / axis=x noclip;
text x=xl y=obsid text=text / position=bottom contributeoffsets=none strip;
yaxistable exposure / location=inside position=left textgroup=id labelattrs=(size=12 Weight=Bold);
yaxistable nobsused / location=inside position=left labelattrs=(size=12 Weight=Bold) valueattrs=(size=9);
yaxistable iqr percent _95/ location=inside position=left;
yaxis reverse display=none;
xaxis labelattrs=(size=12) valueattrs=(size=9);
x2axis min=-100 max=100 values=(-100 to 100 by 10)display=all labelattrs=(size=9) offsetmin=0 offsetmax=0;
xaxis label='Rate (%)' LABELPOS=DATACENTER labelattrs=(color=Black size=9 WEIGHT= BOLD);
run;
Your values list is for an X2AXIS, or the top of the graph. I don't see any plot actually using the X2AXIS though.
Strong hint: ONE Xaxis and ONE Yaxis statement with all the options.
We see cases where multiple statements only have the last Xaxis or Yaxis statement applied.
I also use following ways but didn't get fixed x axis
xaxis values=(-100 to 100 by 10) labelattrs=(size=12) valueattrs=(size=9);
xaxis label='Excess rate (%)' LABELPOS=DATACENTER labelattrs=(color=Black size=9 WEIGHT= BOLD);
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.