BookmarkSubscribeRSS Feed
MingC
Calcite | Level 5

When I'm creating a x-axis table using GTL axistable statement in a layout overlay statement, I find the  x-axis table label (see below part marked as yellow) could not align, I tried to use labelhalign=left or labeljustify=left, but in vain. I also tried tickvaluehalign=left, but doesn't work.Any help are appreciated.  

MingC_1-1757317032795.png

 

proc template;
    define statgraph lineplot;
    begingraph/attrpriority=none datacontrastcolors=(red blue orange);
 
    entrytitle halign=left "&cat."/  textattrs=(size=8) ;
                          
     layout lattice / columns=1 rows=3 rowweights=(0.87 0.03 0.1) columndatarange=union rowdatarange=union;
  
        *cell with line plot;
        layout overlay / yaxisopts=(type=log logopts=(base=2 tickintervalstyle=logexpand
                           tickvaluelist=(32 64 256 1024 4096 16384 65536 262144 1048576 /*4194304 16777216*/) tickvaluepriority=true )
                           label="Median titre" labelattrs=(size=9pt) tickvalueattrs=(size=8pt))
                        xaxisopts=(display=(TICKS TICKVALUES LABEL line) label="Timepoint" labelattrs=(size=9pt) tickvalueattrs=(size=8pt));
 
           seriesplot  x=avisit_wk y=_median / group = AVALCAT display=all groupdisplay = cluster clusterwidth = 0.2 name = 'series';                       
           scatterplot x=avisit_wk y=_median /yerrorlower=_q1 yerrorupper=_q3
             ERRORBARATTRS=(pattern=dot) group = AVALCAT groupdisplay = cluster clusterwidth = 0.2 ;                           
                                                                       
           discretelegend "series" / title='' titleattrs=(size=9pt) valueattrs=(size=9pt)
                                  displayclipped = true across=4 border=false location=outside halign=center valign=bottom;
        endlayout;
               
       *cell with axistable values (n);
         layout overlay ;
            entry halign=left "n"/textattrs=(size=9pt);
         endlayout;
                     
        layout overlay / walldisplay=none halign=left xaxisopts=(tickvalueattrs=(size=8pt) display=none)
                                   /*yaxisopts=(display=(tickvalues ) tickvaluehalign=left)*/;
           axistable x=avisit_wk value=n /display=(label) /*labelhalign=left labeljustify=left*/ valueattrs=(size=9pt) labelattrs=(size=9pt) 
class=AVALCAT colorgroup=AVALCAT;         endlayout;                                               endlayout;     endgraph;   end; run; ods graphics on/noborder;   ods noptitle;

 

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hello @MingC and welcome to the SAS Support Communities!

 


@MingC wrote:

(...) I tried to use labelhalign=left or labeljustify=left, but in vain.


Sadly, the documentation of both these options says:

Restriction This option applies only to Y-axis tables.

@MingC wrote:

I also tried tickvaluehalign=left, but doesn't work.


I think this option does not apply to the axis table.

Unless someone else has a better idea, here is a workaround: Use a non-proportional (a.k.a. fixed-width) font for the labels to be left-aligned and pad the shorter labels with trailing non-breaking spaces so that they match the length of the longest label.

 

Example:

 

data have;
set sashelp.prdsale;
if division=:'E' then division='EDU';
run;

Using the PROC TEMPLATE example code from the AXISTABLE documentation, the x-axis table obtained with

proc sgrender data=have template=axistable;
run;

looks like this:

Default alignmentDefault alignment

After inserting the below LABELATTRS= option into the AXISTABLE statement of the PROC TEMPLATE code

...
headerlabelattrs=GraphLabelText
labelattrs=(family='Lucida Console' size=11pt)
valueattrs=(size=9pt weight=bold)
...

and modifying the short "EDU" value,

data want;
set have;
if division='EDU' then division='EDU'||'A0A0A0A0A0'x;
run;

proc sgrender data=want template=axistable;
run;

left-alignment is achieved:

Left-alignedLeft-aligned

MingC
Calcite | Level 5

@FreelanceReinh , thank you very much for your quick and detailed response. I was wondering if I there is a proc template options could fix the alignment, which bothered me in the past couple of weeks. After I tried your idea to add 'A0A0A0A0A0'x to the end of shorter label value, I can left-align the label now. I'll accept your idea as solution if no better idea appears in one month.

MingC_0-1757383624272.png

 

FreelanceReinh
Jade | Level 19

@MingC wrote:

@FreelanceReinh , thank you very much for your quick and detailed response. I was wondering if I there is a proc template options could fix the alignment, which bothered me in the past couple of weeks. After I tried your idea to add 'A0A0A0A0A0'x to the end of shorter label value, I can left-align the label now.


You're welcome. There doesn't seem to be a PROC TEMPLATE option to control that alignment. Glad to hear that the 'A0'x trick worked for you. (The minor imperfection in the alignment shown in your screenshot is due to the proportional font you are using.)

 

Another approach would be SG annotation. Continuing the example from the previous post:

%sganno;

data anno;
%sgtext(reset=all, id="xtlabel", label="EDU", textcolor="GraphData1:contrastcolor", textsize=9, textweight="bold",
        x1=0, x1space="layoutpixel", y1=69, y1space="layoutpixel", anchor="left");
%sgtext(label="CONSUMER", textcolor="GraphData2:contrastcolor", width=90, y1=55);
run;

proc template;
  define statgraph axistable;
    begingraph; 
      entrytitle "Average Product Sales By Division and Country";
      layout overlay / cycleattrs=true pad=(left=18px) 
        yaxisopts=(offsetmax=0.15 label="Sales By Country"); 
        innermargin / align=bottom opaque=true backgroundcolor=cxf5f5f5;
          axistable x=product value=actual / 
            name="division" stat=mean display=(values)
            headerlabel="Sales By Division"
            headerlabelattrs=GraphLabelText
            valueattrs=(size=9pt weight=bold)
            colorgroup=division class=division;
        endinnermargin;
        barchart category=product y=actual / name="country" 
          barlabel=true barlabelformat=dollar5.0
          stat=mean group=country groupdisplay=cluster;
        discretelegend "country" / title="Country:" location=inside
          valign=top;
        annotate / ID="xtlabel"; 
      endlayout; 
   endgraph;
 end;
run;

proc sgrender data=have template=axistable sganno=anno;
run;

The display=(values) option in the AXISTABLE statement suppresses the original labels, which are then replaced by the labels (here: hard-coded) in the annotation dataset ANNO. The new pad= option of the LAYOUT statement provides the space on the left needed for those labels. Their vertical positioning (i.e., determining the y1 coordinates) is cumbersome.

 

Result:

Using SG annotationUsing SG annotation

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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