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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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