BookmarkSubscribeRSS Feed
linlin87
Quartz | Level 8

Hello SAS Community,

I use band to annotate graph with gray box. But I need box to finish at x=0, and it keep going. How I stop the grey box at 0, just get the yellow area (below)?

linlin87_0-1690878827221.png

I use code: 


data boundary;
do x = -0.002 to 0 by .00001;            
	up1=0;
	output;
end;
run;
 
data plot;
set plot_data boundary;
run;

proc sgplot data=plot;
   band x=x upper=0 lower=-0.002 / fillattrs=(transparency=0.5 color=gray);
   yaxis max = 0.005 grid;
   xaxis max = 0.005 grid;
run;

Thank you for help!

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hello @linlin87,

 

I think the issue is that you specify a constant value in the UPPER= option of the BAND statement rather than the variable UP1, which you defined in the BOUNDARY dataset. So try this:

band x=x upper=up1 lower=-0.002 / fillattrs=(transparency=0.5 color=gray);

 

Depending on the content of dataset PLOT_DATA and how you use it in your real PROC SGPLOT step, other techniques to limit the gray box include:

  • the NOEXTEND option of the BAND statement
  • defining a step function in the BOUNDARY dataset:
    data boundary;
    do x = -0.002 to 0.005 by .0001; 
      x=round(x,1e-9);
      if x<=0 then up1=0;
      else up1=-0.002;
      output;
    end;
    run;

If the box doesn't look exactly rectangular, you may also want to add the TYPE=STEP option to the BAND statement.

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 190 views
  • 0 likes
  • 2 in conversation