I'm using SGPANEL, and would like to highlight certain panels that are interesting. I think I just want a way to set the wallcolor for each panel dynamically, is that possible?
Below code will make 3 panels, and all three will have the wallcolor set to yellow:
data have ;
input panelid x y ;
cards ;
1 10 10
1 20 20
2 10 15
2 20 15
3 10 20
3 20 10
;
proc sgpanel data=have ;
panelby panelid/ layout=panel;
styleattrs wallcolor="yellow" ;
series x=x y=y;
run ;
Is there a way I can make only the second panel have a yellow wallcolor?
I tried using a band plot in the background, which came close, but still extended the y-axis even though I set option NOEXTEND. I'm sure I could try other methods for adding a yellow bar in the background of second panel (e.g. REFLINE instead of a BAND), but before I go down that path, wondered if I'm missing an easier way.
My band plot approach:
data want ;
set have ;
if panelid=2 then do ;
lowerband=0 ;
upperband=100 ;
end ;
run ;
proc sgpanel data=want ;
panelby panelid/ layout=panel;
band x=x lower=lowerband upper=upperband /fillattrs=(color=yellow) noextend;
series x=x y=y;
run ;
Returned:
How about using the BLOCK plot for the highlighting, like so:
data want ;
set have ;
if panelid=2 then do ;
block = "highlight";
end ;
run ;
proc sgpanel data=want ;
panelby panelid/ layout=panel;
block x=x block=block /
/* novalues*/
class=block nomissingclass
fill fillattrs=(color=cornsilk) FILLTYPE=alternate
;
series x=x y=y;
run ;
It would even allow you to say why its background is different. You can switch of the text using NOVALUES. The additional CLASS= and NOMISSINGCLASS makeit easy to only display it for the panel wanted.
Using an attribute map you even have more possibilities:
data attrmap;
retain ID "myid";
length value fillcolor $ 16;
input value fillcolor filltransparency;
datalines;
highlight gold 0
_OTHER_ lightgrey 1
;
proc sgpanel data=want dattrmap=attrmap ;
panelby panelid/ layout=panel;
block x=x block=block /
novalues
attrid=myid
filltype=multicolor
;
series x=x y=y;
run ;
Quentin,
You could use options "offsetmin=0 offsetmax=0" to eliminate these cell padding.
proc sgpanel data=want ;
panelby panelid/ layout=panel;
band x=x lower=lowerband upper=upperband /fillattrs=(color=yellow) noextend;
series x=x y=y;
colaxis offsetmin=0 offsetmax=0;
rowaxis offsetmin=0 offsetmax=0;
run ;
Quentin, A more sophisticated way is using built-in %SGANNO macro .
data have ;
input panelid x y ;
cards ;
1 10 10
1 20 20
2 10 15
2 20 15
3 10 20
3 20 10
;
%sganno;
data sganno;
%SGRECTANGLE(
X1=53,
Y1=53,
HEIGHT=42,
WIDTH=45,
ANCHOR="BOTTOMLEFT" ,
DISPLAY="FILL",
DRAWSPACE="GRAPHPERCENT" ,
FILLCOLOR="yellow" ,
LAYER="BACK"
)
run;
proc sgpanel data=have sganno=sganno ;
panelby panelid/ layout=panel nowall;
series x=x y=y;
run ;
How about using the BLOCK plot for the highlighting, like so:
data want ;
set have ;
if panelid=2 then do ;
block = "highlight";
end ;
run ;
proc sgpanel data=want ;
panelby panelid/ layout=panel;
block x=x block=block /
/* novalues*/
class=block nomissingclass
fill fillattrs=(color=cornsilk) FILLTYPE=alternate
;
series x=x y=y;
run ;
It would even allow you to say why its background is different. You can switch of the text using NOVALUES. The additional CLASS= and NOMISSINGCLASS makeit easy to only display it for the panel wanted.
Using an attribute map you even have more possibilities:
data attrmap;
retain ID "myid";
length value fillcolor $ 16;
input value fillcolor filltransparency;
datalines;
highlight gold 0
_OTHER_ lightgrey 1
;
proc sgpanel data=want dattrmap=attrmap ;
panelby panelid/ layout=panel;
block x=x block=block /
novalues
attrid=myid
filltype=multicolor
;
series x=x y=y;
run ;
Maybe with additional:
valueattrs=(color=cornsilk)
to hide the "highlight" text? 🙂
Bart
Thanks so much @BrunoMueller . Really appreciate you adding the attrmap example, it's exactly what I need in order to keep the highlighting consistent. The block chart is working perfectly.
When I started with ODS graphics I started with GTL. But about a year later I realized how much customization you could do with SGPLOT and SGPANEL, and it always amazes me how flexible they are.
@Quentin you are welcome. I went through the same process, needed many times GTL, but then SGPLOT got more and more features and it got a lot easier to do special stuff.
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.