Desktop productivity for business analysts and programmers

Change the names in alegend in an SGPLOT

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 129
Accepted Solution

Change the names in alegend in an SGPLOT

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

 

 


Accepted Solutions
Solution
‎07-06-2018 12:44 AM
Esteemed Advisor
Posts: 5,624

Re: Change the names in alegend in an SGPLOT

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


All Replies
Solution
‎07-06-2018 12:44 AM
Esteemed Advisor
Posts: 5,624

Re: Change the names in alegend in an SGPLOT

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
Frequent Contributor
Posts: 129

Re: Change the names in alegend in an SGPLOT

Thanks @PGStats

 

Works now.

 

Cheers

Dean 

 

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 91 views
  • 1 like
  • 2 in conversation