BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

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:

Quentin_0-1715615469961.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

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 ;

BrunoMueller_0-1715677410949.png

 

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 ;

View solution in original post

7 REPLIES 7
Ksharp
Super User

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 ;

Ksharp_0-1715657511473.png

 

Ksharp
Super User

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 ;

Ksharp_0-1715658356461.png

 

BrunoMueller
SAS Super FREQ

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 ;

BrunoMueller_0-1715677410949.png

 

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 ;
yabwon
Amethyst | Level 16

Maybe with additional: 

valueattrs=(color=cornsilk)

to hide the "highlight" text? 🙂 

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



BrunoMueller
SAS Super FREQ
You can use the NOVALUES to hide the text
Quentin
Super User

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.

BrunoMueller
SAS Super FREQ

@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.

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
  • 7 replies
  • 2291 views
  • 15 likes
  • 4 in conversation