Hi All,
I am trying to work out how to change the name in a SGPLOT legend. I'm using 1,2 and 3 to order the grouping in the bar chart
1 = ATT
2= AHold
3= AWT
How do I now give the legend 'meaningful' names.
I'm using SAS 9.4
My code looks similar to this
Data test;
Input date $ count average type;
Datalines;
43252 2124 515 1
43252 2124 162 2
43252 2124 166 3
43255 2984 491 1
43255 2984 156 2
43255 2984 171 3
43256 2713 518 1
43256 2713 153 2
43256 2713 161 3
43257 2540 509 1
43257 2540 156 2
43257 2540 157 3
;
RUN;
Proc SGPLOT data=test;
HBAR date / Response=average Group=type datalabel seglabel;
xaxis display=(noline noticks) grid values=(0 to 1200 by 150) offsetmin=0;
RUN;
and my output looks like this
any help appreciated
Cheers
Dean
Try using a format and option grouporder as an extra precaution:
proc sort data=test; by date type; run;
proc format;
value typeFmt
1 = "ATT"
2 = "AHold"
3 = "AWT"
;
Proc SGPLOT data=test;
format type typeFmt.;
HBAR date / Response=average Group=type grouporder=data datalabel seglabel;
xaxis display=(noline noticks) grid values=(0 to 1200 by 150) offsetmin=0;
RUN;
Try using a format and option grouporder as an extra precaution:
proc sort data=test; by date type; run;
proc format;
value typeFmt
1 = "ATT"
2 = "AHold"
3 = "AWT"
;
Proc SGPLOT data=test;
format type typeFmt.;
HBAR date / Response=average Group=type grouporder=data datalabel seglabel;
xaxis display=(noline noticks) grid values=(0 to 1200 by 150) offsetmin=0;
RUN;
Hi,
I have the same problem, but in my case the "group" is not numeric type, but character.
For example my group variable "age" is "young" and "old" and I want to have on the legend: "young age" "old age".
How can I do?
Thanks!
Use a user defined character format:
proc format;
value $ageFmt
"old" = "old age"
"young" = "young age"
;
Proc SGPLOT data=test;
format age $ageFmt.;
HBAR date / Response=average Group=age grouporder=data datalabel seglabel;
xaxis display=(noline noticks) grid values=(0 to 1200 by 150) offsetmin=0;
RUN;
(untested)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.