Data visualization with SAS programming

sgpanel - showing group on axis

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

sgpanel - showing group on axis

any suggestions on how I can get the group variable on the axis?

(like was available with gchart, using group = and subgroup =)

 

Sample code - I'd like the year field to show on the column axis (along with the q field)


data a; input q $ year id $ pct;
cards;
4yr 2013 d 0.44
2yr 2013 d 0.43
4yr 2014 d 0.29
2yr 2014 d 0.63
4yr 2013 i 0.58
2yr 2013 i 0.31
4yr 2014 i 0.54
2yr 2014 i 0.34
;
run;
proc sgpanel data=a noautolegend;
panelby id/columns=2 rows=1;
hbar q / response=pct group =year GROUPDISPLAY=CLUSTER;
run;


Accepted Solutions
Solution
‎04-08-2016 04:29 PM
SAS Super FREQ
Posts: 1,141

Re: sgpanel - showing group on axis

Here are some additional ideas.  Should work with SGPANEL, but did nto verify.

 

http://blogs.sas.com/content/graphicallyspeaking/2016/04/08/displaying-group-values-on-axis/

 

View solution in original post


All Replies
SAS Super FREQ
Posts: 1,141

Re: sgpanel - showing group on axis

Since you have explicitly turned off the AUTOLEGEND, you can overlay the group value on the bar.  If you have SAS 9.4, you can use the TEXT plot.  Else, you can use the SCATTER with MARKERCHAR.  But to overlay on a bar, you have to use HBARPARM, which is OK since you are not expecting the bar char to summarize data.  If you do, you will have to presummarize your data using PROC MEANS, then use HBARPARM.

 

Note addition of the variable XLBL=0.

 

data a;
input q $ year id $ pct;
xlbl=0;
cards;
4yr 2013 d 0.44
2yr 2013 d 0.43
4yr 2014 d 0.29
2yr 2014 d 0.63
4yr 2013 i 0.58
2yr 2013 i 0.31
4yr 2014 i 0.54
2yr 2014 i 0.34
;
run;

 

proc sgpanel data=a noautolegend;
panelby id/columns=2 rows=1;
hbarparm category=q response=pct / group =year GROUPDISPLAY=CLUSTER;
text x=xlbl y=q text=year / group=year groupdisplay=cluster position=right textattrs=(color=black);

colaxis offsetmin=0;
run;

 

You can creatively put the value anywhere, even rotate it vertically at the base of the bar.

GroupLabel.png

Contributor
Posts: 27

Re: sgpanel - showing group on axis

Thanks! - any way I can get the year value on the left side of the axis line? (tried a number of options, with no luck)
Solution
‎04-08-2016 04:29 PM
SAS Super FREQ
Posts: 1,141

Re: sgpanel - showing group on axis

Here are some additional ideas.  Should work with SGPANEL, but did nto verify.

 

http://blogs.sas.com/content/graphicallyspeaking/2016/04/08/displaying-group-values-on-axis/

 

Contributor
Posts: 27

Re: sgpanel - showing group on axis

thanks - lots of good ideas! I haven't been able to get sgpanel to work, but your solution provided what I needed (I can use "ods layout gridded columns=2" to get where I want to go)
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 462 views
  • 1 like
  • 2 in conversation