Data visualization with SAS programming

My datalabel position is not in Center even after I use DATALABELPOS=CENTER

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

My datalabel position is not in Center even after I use DATALABELPOS=CENTER

I need to create a plot with MY2R values in the symbol center. But even I used DATALABELPOS=CENTER, all the data labels shift to right and not in the center. Could someone please help me with it? Thanks. 

 

Here is my code:


PROC SGPLOT DATA = temp1 dattrmap=attrmap noborder;


Scatter Y=NAME X = MY2R/markerAttrs=(COLOR=purple size=6MM symbol=CIRCLEFILLED)  datalabel=MY2R DATALABELATTRS=(size=9pt weight=bold COLOR=White) DATALABELPOS=CENTER transparency=0.1;

 

XAXIS DISPLAY=(NOTICKS) label=' ' labelattrs=(size=8pt color=Black) values=(60 to 100 by 20) valueattrs=(size=8pt Family=Arial color=black); 

run;


Accepted Solutions
Solution
‎12-21-2017 02:28 PM
SAS Super FREQ
Posts: 1,199

Re: My datalabel position is not in Center even after I use DATALABELPOS=CENTER

Posted in reply to hanyi0221

Make sure you do not have leading blanks in your labels.  Also, you can use a TEXT plot to display labels with the STRIP option.

View solution in original post


All Replies
Solution
‎12-21-2017 02:28 PM
SAS Super FREQ
Posts: 1,199

Re: My datalabel position is not in Center even after I use DATALABELPOS=CENTER

Posted in reply to hanyi0221

Make sure you do not have leading blanks in your labels.  Also, you can use a TEXT plot to display labels with the STRIP option.

SAS Super FREQ
Posts: 442

Re: My datalabel position is not in Center even after I use DATALABELPOS=CENTER

Posted in reply to Sanjay_SAS

Following up on @Sanjay_SAS, these steps illustrate a character variable (centered), a numeric variable (and hence leading blanks) (does not appear centered), and a numeric to character conversion and left justification before plotting (centered).

proc sgplot data=sashelp.class;
   scatter y=weight x=height / datalabel=name datalabelpos=center;
quit;

proc sgplot data=sashelp.class;
   scatter y=weight x=height / datalabel=age datalabelpos=center;
quit;

data class;
   set sashelp.class;
   age2 = cats(age);
run;   

proc sgplot data=class;
   scatter y=weight x=height / datalabel=age2 datalabelpos=center;
quit;
Highlighted
Occasional Contributor
Posts: 16

Re: My datalabel position is not in Center even after I use DATALABELPOS=CENTER

Posted in reply to WarrenKuhfeld

Thank you Warren, this is very helpful and I will save your post as future reference.

Occasional Contributor
Posts: 16

Re: My datalabel position is not in Center even after I use DATALABELPOS=CENTER

Posted in reply to Sanjay_SAS

Thank you Sanjay! My labels do have leading blanks.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 152 views
  • 1 like
  • 3 in conversation