BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12
I'm writing on my Android hence cannot insert the code.
My plot combines Hbar statement and a yaxistable and it does so satisfactory.
But I cannot manage to get the labels from the axistable to the top.
I suppose that due to lack of space it gets moved to the bottom whatever I try. The Labelpos option doesn't fix the problem either.
Any idea?
1 ACCEPTED SOLUTION

Accepted Solutions
SuzanneDorinski
Lapis Lazuli | Level 10

To make the the percentages on the left show as negative numbers, you can  use VALUESDISPLAY= option on the XAXIS statement. 

 

I read the What you need to know about the graph template and data object in PROC SGPLOT blog post by Warren Kuhfeld.   I added the TMPLOUT= option on the PROC SGPLOT statement, and used the ODS OUTPUT statement to write the data object to a SAS data set.  

 

The data object shows the values in the same order as your TRY data set.  In the graph template, I see that labelposition=max. 

 

If you only do one HBAR statement with the axis table, the labels show up at the top, and the graph template shows labelposition=min. 

 

There's some interaction when you do two HBAR statements with the axis table, and then labelposition=max in the graph template, which means the labels are at the bottom.  

 

You can force the labels to the top by using LABELPOS=BOTTOM.  That seems backwards, but perhaps Sanjay can provide a better method to get what you want.

 

I don't know how to control the column widths of the y axis table.  

 

Updated code is below.

 

ods graphics / height=11in;

title "Comparison" ;
PROC SGPLOT DATA=WORK.TRY tmplout='/folders/myfolders/ODS Graphics/tmpl';
  ods output sgplot=dataobject;
FORMAT  DIFF: POSITIVER. M V PERCENT9.2;
LABEL PERC="% DE LA MUESTRA" MM="#BRAND" MV="#BANK"; 

HBAR NAME / RESPONSE=DIFFNEG 
TRANSPARENCY=0 DATASKIN=SHEEN FILLATTRS=(COLOR=GRGY) 
LEGENDLABEL="BRAND PERFORMS BETTER" NAME="DIFS1";

HBAR NAME / RESPONSE=DIFFPLUS 
TRANSPARENCY=0 DATASKIN=SHEEN FILLATTRS=(COLOR=LIGHTBLUE) 
LEGENDLABEL="BANK PERFORMS BETTER" NAME="DIFS";

YAXISTABLE PERC M MM V MV  / LABELATTRS=(SIZE=8PT)  
VALUEATTRS=(SIZE=8PT COLOR=STBG ) LABELPOS=bottom LABELJUSTIFY=LEFT    ;

KEYLEGEND "DIFS" "DIFS1"       / ACROSS=2  ;  
XAXIS DISPLAY=(NOLABEL) VALUES=(-0.06 TO 0.06 BY 0.01) GRID
     valuesdisplay=('-6,0%' '-5,0%' '-4,0%' '-3,0%' '-2,0%' '-1,0%' ''
                    '1,0%' '2,0%' '3,0%' '4,0%' '5,0%' '6,0%');
YAXIS DISPLAY=(NOLABEL) DISCRETEORDER=DATA GRID GRIDATTRS=(COLOR=GRAY THICKNESS=0.1 PATTERN=35);

RUN;

The graphic is below.

 

PROC SGPLOT with two HBAR plots and a YAXISTABLE statementPROC SGPLOT with two HBAR plots and a YAXISTABLE statement

View solution in original post

5 REPLIES 5
Jay54
Meteorite | Level 14

It is easier to help if you post your code with sample data.  Also SAS version.

acordes
Rhodochrosite | Level 12

For sure. 

Thanks to the SAS Jedi trick The DATA to DATA Step Macro https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/ I can generate the data set:

 

DATA WORK.TRY;
  INFILE DATALINES DSD TRUNCOVER;
  INPUT DIFF:PERCENT9.2 PERC:PERCENT9. M:32. V:32. MAX:32. MIN:32. DIFFPLUS:32. DIFFNEG:32. MV:32. MM:32. OBS:32. NAME:$57. COMP:$22.;
DATALINES4;
(  1.63%),34%,0.5953204496,0.6116648155,0.6116648155,0.5953204496,-0.016344366,,641,482,1,L1,V_WINS
0.04%,19%,0.6064239733,0.6060735665,0.6064239733,0.6060735665,,0.0003504068,359,256,2,L2,M_WINS
(  0.31%),16%,0.5932613868,0.5963613685,0.5963613685,0.5932613868,-0.003099982,,275,266,3,I3,V_WINS
1.91%,16%,0.5729693443,0.5538312623,0.5729693443,0.5538312623,,0.019138082,332,190,4,I4,M_WINS
1.61%,7%,0.5588098603,0.5427254229,0.5588098603,0.5427254229,,0.0160844374,204,22,5,T5,M_WINS
(  4.92%),4%,0.5404668375,0.5897045724,0.5897045724,0.5404668375,-0.049237735,,55,84,6,A6,V_WINS
1.41%,1%,0.7134496412,0.6993465515,0.7134496412,0.6993465515,,0.0141030897,6,20,7,A7,M_WINS
(  5.41%),1%,0.5602382022,0.6143416111,0.6143416111,0.5602382022,-0.054103409,,3,20,8,M8,V_WINS
4.05%,1%,0.6105264617,0.5699828477,0.6105264617,0.5699828477,,0.0405436141,2,20,9,L9,M_WINS
(  0.95%),1%,0.6177154876,0.6272112139,0.6272112139,0.6177154876,-0.009495726,,2,20,10,L10,V_WINS
0.00%,1%,0.6787155622,,0.6787155622,0.6787155622,,0,,20,11,A11,M_WINS
0.00%,0%,,0.62606918,0.62606918,0.62606918,,0,12,,12,L12,V_WINS
0.00%,0%,,0.6433033764,0.6433033764,0.6433033764,,0,9,,13,L13,V_WINS
0.00%,0%,,0.6073440585,0.6073440585,0.6073440585,,0,6,,14,L14,V_WINS
0.00%,0%,,0.6612735808,0.6612735808,0.6612735808,,0,1,,15,L15,V_WINS
;;;;
PROC FORMAT;
   PICTURE POSITIVER 
     LOW-<0='000,000.00,0%'
     0<-HIGH='000,000.00,0%';
RUN;

title "Comparison" ;
PROC SGPLOT DATA=WORK.TRY  ;
FORMAT  DIFF: POSITIVER. M V PERCENT9.2;
LABEL PERC="% DE LA MUESTRA" MM="#BRAND" MV="#BANK"; 

/*HBAR NAME / RESPONSE=DIFF GROUP=COMP*/
/*TRANSPARENCY=0 DATASKIN=SHEEN  */
/*LEGENDLABEL="DIFFERENCE BETWEEN DATA SOURCES" NAME="DIFS";*/

HBAR NAME / RESPONSE=DIFFPLUS 
TRANSPARENCY=0 DATASKIN=SHEEN FILLATTRS=(COLOR=LIGHTBLUE) 
LEGENDLABEL="BANK PERFORMS BETTER" NAME="DIFS";

HBAR NAME / RESPONSE=DIFFNEG 
TRANSPARENCY=0 DATASKIN=SHEEN FILLATTRS=(COLOR=GRGY) 
LEGENDLABEL="BRAND PERFORMS BETTER" NAME="DIFS1";

YAXISTABLE PERC M MM V MV  / LABELATTRS=(SIZE=8PT)  
VALUEATTRS=(SIZE=8PT COLOR=STBG ) LABELPOS=TOP LABELJUSTIFY=LEFT    ;

KEYLEGEND "DIFS" "DIFS1"       / ACROSS=2  ;  
XAXIS DISPLAY=(NOLABEL) VALUES=(-0.06 TO 0.06 BY 0.01) GRID;
YAXIS DISPLAY=(NOLABEL) DISCRETEORDER=DATA GRID GRIDATTRS=(COLOR=GRAY THICKNESS=0.1 PATTERN=35);

RUN;

ODS.png

 

I would like to move the labels to the TOP. Furthermore I'd like to control and unify the column width of the YAXISTABLE. 

And I don't know how to convert the percentage range towards the left to negative.

 

Thanks a lot, 

bye, Arne 

SuzanneDorinski
Lapis Lazuli | Level 10

To make the the percentages on the left show as negative numbers, you can  use VALUESDISPLAY= option on the XAXIS statement. 

 

I read the What you need to know about the graph template and data object in PROC SGPLOT blog post by Warren Kuhfeld.   I added the TMPLOUT= option on the PROC SGPLOT statement, and used the ODS OUTPUT statement to write the data object to a SAS data set.  

 

The data object shows the values in the same order as your TRY data set.  In the graph template, I see that labelposition=max. 

 

If you only do one HBAR statement with the axis table, the labels show up at the top, and the graph template shows labelposition=min. 

 

There's some interaction when you do two HBAR statements with the axis table, and then labelposition=max in the graph template, which means the labels are at the bottom.  

 

You can force the labels to the top by using LABELPOS=BOTTOM.  That seems backwards, but perhaps Sanjay can provide a better method to get what you want.

 

I don't know how to control the column widths of the y axis table.  

 

Updated code is below.

 

ods graphics / height=11in;

title "Comparison" ;
PROC SGPLOT DATA=WORK.TRY tmplout='/folders/myfolders/ODS Graphics/tmpl';
  ods output sgplot=dataobject;
FORMAT  DIFF: POSITIVER. M V PERCENT9.2;
LABEL PERC="% DE LA MUESTRA" MM="#BRAND" MV="#BANK"; 

HBAR NAME / RESPONSE=DIFFNEG 
TRANSPARENCY=0 DATASKIN=SHEEN FILLATTRS=(COLOR=GRGY) 
LEGENDLABEL="BRAND PERFORMS BETTER" NAME="DIFS1";

HBAR NAME / RESPONSE=DIFFPLUS 
TRANSPARENCY=0 DATASKIN=SHEEN FILLATTRS=(COLOR=LIGHTBLUE) 
LEGENDLABEL="BANK PERFORMS BETTER" NAME="DIFS";

YAXISTABLE PERC M MM V MV  / LABELATTRS=(SIZE=8PT)  
VALUEATTRS=(SIZE=8PT COLOR=STBG ) LABELPOS=bottom LABELJUSTIFY=LEFT    ;

KEYLEGEND "DIFS" "DIFS1"       / ACROSS=2  ;  
XAXIS DISPLAY=(NOLABEL) VALUES=(-0.06 TO 0.06 BY 0.01) GRID
     valuesdisplay=('-6,0%' '-5,0%' '-4,0%' '-3,0%' '-2,0%' '-1,0%' ''
                    '1,0%' '2,0%' '3,0%' '4,0%' '5,0%' '6,0%');
YAXIS DISPLAY=(NOLABEL) DISCRETEORDER=DATA GRID GRIDATTRS=(COLOR=GRAY THICKNESS=0.1 PATTERN=35);

RUN;

The graphic is below.

 

PROC SGPLOT with two HBAR plots and a YAXISTABLE statementPROC SGPLOT with two HBAR plots and a YAXISTABLE statement

acordes
Rhodochrosite | Level 12

Furthermore I wonder if I can use the group option in the HBAR statement WITHOUT affecting the YAXISTABLE. If I do so, and in this case having 2 levels in the group, I get twice the number of columns as it is split by group.

acordes
Rhodochrosite | Level 12

Dear @Jay54 , I think that I've delivered code and example Smiley Happy

I'm running EG version 7.13

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 5338 views
  • 1 like
  • 3 in conversation