BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DME790
Pyrite | Level 9

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

 

Capture10.JPG

 

 

any help appreciated

 

Cheers

 

Dean

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;
PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

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;
PG
DME790
Pyrite | Level 9

Thanks @PGStats

 

Works now.

 

Cheers

Dean 

 

marta25
Obsidian | Level 7

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!

PGStats
Opal | Level 21

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)

PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3525 views
  • 2 likes
  • 3 in conversation