BookmarkSubscribeRSS Feed
fastb
Fluorite | Level 6

The attached graph was created in PROC SGPLOT. I want the gray band to extend the full width of the plot.  However, I would like the data points to stay where they are.  Any suggestions?


Graph Example.PNG
2 REPLIES 2
GraphGuy
Meteorite | Level 14

I'm not sure how to do it in sgplot, but you can do it in gplot by annotating the gray shaded range ...

data foo;
input entry $ 1-7 value group;
datalines;
Entry A 1.20 1
Entry A 1.25 2
Entry A 1.50 3
Entry A 1.60 4
Entry B 1.23 1
Entry B 1.41 2
Entry B 1.52 3
Entry B 1.61 4
;
run;

data anno_range;
xsys='1'; ysys='2'; when='b';
function='move'; x=0; y=1.2; output;
function='bar'; x=100; y=1.6; color='graydd'; style='solid'; output;
run;

symbol1 value=circle interpol=none color=black;
symbol2 value=triangle interpol=none color=black;
symbol3 value='x' interpol=none color=black;
symbol4 value=plus interpol=none color=black;

axis1 label=none minor=none order=(0 to 2.0 by .2) offset=(0,0);
axis2 label=none offset=(30,30);

proc gplot data=foo anno=anno_range;
plot value*entry=group / vaxis=axis1 haxis=axis2 nolegend;
run;

Jay54
Meteorite | Level 14

Band.png

The "constant" bands are extended to the edge only if the X variable is numeric.  So, change your X variable to numeric, and add a UDF for the labels and set x axis offsets to 0.2.

proc sgplot data=BandNum;

  band x=x upper=1.5 lower=1.05;

  scatter x=x y=y / group=group name='a';

  yaxis values=(0 to 2 by 0.2) display=(nolabel);

  xaxis offsetmin=0.2 offsetmax=0.2 display=(nolabel) values=(1 2);

  keylegend 'a' / location=inside position=topright;

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1822 views
  • 0 likes
  • 3 in conversation