Data visualization with SAS programming

How to make axis label bigger?

Reply
Contributor
Posts: 70

How to make axis label bigger?

This is sample program:


data temp;
input Item $ Avg;
datalines;
Item1 2.5
Item2 4.3
Item3 3.8
Item4 4.8
Item5 4.5
;
run;

proc sgplot data=temp;
xaxis label="Mean Response Score" values=(1 to 5 by 1);
yaxis label="Survey Items";
hbar Item / datalabel response=Avg ;
run;
quit;

I like to make a xaxis label bigger. Based on the SAS documentation, I modified the xaxis statement as:

xaxis label=(HEIGHT=12pt "Mean Response Score") values=(1 to 5 by 1);

which cause syntax error. I am confused about how to use these text suboptions with proc sgplot.
Thanks.
SAS Super FREQ
Posts: 890

Re: How to make axis label bigger?

Hey,

The syntax you used for the label is from the AXIS statement in SAS/GRAPH. The axis statements in the SG procedures are different. Currently, the procedure syntax for controlling the axis text attributes is not there. There are a couple of ways to work around this.

1) You can create a small style like the following and use it on your ODS statement. The drawback (or bonus) is that it will also affect other value-related text in your graph.
[pre]
proc template;
define style styles.bigtext;
parent=styles.listing;
style GraphValueText from GraphValueText /
fontsize=12pt
;
end;
run;
[/pre]
2) You can use GTL (graph template language) to create the graph where you will have control over text attributes. The template to create your graph would be the following:
[pre]
proc template;
define statgraph barchart;
begingraph;
layout overlay / xaxisopts=( Label="Mean Response Score" labelattrs=(size=12pt)
linearopts=( tickvaluelist=( 1 2 3 4 5 ) viewmin=1 viewmax=5 ) )
yaxisopts=( reverse=true Label="Survey Items" labelattrs=(size=12pt));
BarChart X=Item Y=Avg / orient=horizontal barlabel=true;
endlayout;
endgraph;
end;
run;

proc sgrender data=temp template=barchart; run;
[/pre]

Hope this helps,
Dan
Contributor
Posts: 70

Re: How to make axis label bigger?

Thanks Dan.

Well, this does solve my label size problem. However, I don't know whether this way can keep the options I set in proc sgplot. For example, In proc sgplot, I can use tickvalueformat option to format the tick value, and I can use proc format to format the yaxis text tick values, and I can set the bigger font size of the data label beside each bar.
What are the equivalent ways to implement these parts in your way?

By the way, SAS provides a lot and very good documentations, but if they can come with examples especial when there are many options, then they become more helpful. Just take reference the documentations for other languages from Microsoft.

Thanks
SAS Super FREQ
Posts: 890

Re: How to make axis label bigger?

Inside of the yaxisopts=(), add this:

linearopts=(tickvalueformat=)

For the bar labels, add this to your BARCHART statement:

barlabelattrs=(size=12pt)

-- Dan
Contributor
Posts: 70

Re: How to make axis label bigger?

Thanks again, Dan.

But seems 'linearopts=(tickvalueformat=)' doesn't have any effect on yaxis tick values, but without any syntax error.

Please try this:

data temp;
input Item $ Avg;
datalines;
Item1 2.5
Item2 4.3
Item3 3.8
Item4 4.8
Item5 4.5
;
run;

proc format;
value levelfmt
1='1\nStrongly Disagree'
5='5\nStrongly Agree';
value $itemfmt
'Item1'= 'My survey item1'
'Item2' ='My survey item2'
'Item3' ='My survey item3'
'Item4'= 'My survey item4'
'Item5' ='This is a long survey item,\nso I try to break it in two lines';
run;

proc template;
define statgraph barchart;
begingraph;
layout overlay / xaxisopts=( Label="Mean Response Score" labelattrs=(size=14pt)
linearopts=( tickvaluelist=( 1 2 3 4 5 ) viewmin=1 viewmax=5 ) linearopts=(tickvalueformat=levelfmt.) )
yaxisopts=( reverse=true Label="Survey Items" labelattrs=(size=12pt) linearopts=(tickvalueformat=$itemfmt.));
BarChart X=Item Y=Avg / orient=horizontal barlabel=true barlabelattrs=(size=12pt); endlayout; endgraph; end;
run;

proc sgrender data=temp template=barchart; run;
SAS Super FREQ
Posts: 890

Re: How to make axis label bigger?

I forgot you were doing a horizontal bar chart. You need to put that option on the xaxisopts instead of the yaxisopts.

Sorry about the confusion.

Thanks,
Dan
Contributor
Posts: 70

Re: How to make axis label bigger?

No, I have set this option at xaxisopts correcly, which displays value 1 as '1 Strongly Disagree' and 5 as '5 Strongly Agree'. I think that option you mentioned should go to yaxisopts, but it doesn't work.

By the way, in my enhanced editor (SAS 9.2 Level 2M3), keywords BEGINGRAPH, LAYOUT, BARCHART, ENDLAYOUT and ENDGRAPH all are shown as red color, which normally mean typo or syntax errors. But the program compiled and ran without error. Why? thanks.
SAS Super FREQ
Posts: 890

Re: How to make axis label bigger?

The reason it did not work for the yaxisopts is that the axis is discrete, not linear. The TICKVALUEFORMAT is not supported in discreteopts. To make it work, I would just use a format statement with PROC SGRENDER:

proc sgrender data=temp template=barchart;
format Item $itemfmt.;
run;

Let me know if that works for you.

Thanks!
Dan
SAS Super FREQ
Posts: 890

Re: How to make axis label bigger?

To answer your other question, the syntax checking in the SAS Display Manager does not understand the GTL inside of PROC TEMPLATE. However, the editor in Enterprise Guide 4.3 does support the GTL syntax, including colorization, autocompletion, and tooltip documentation. It's pretty nice :-)

-- Dan
Contributor
Posts: 70

Re: How to make axis label bigger?

Thanks for the in time support, Dan. Now my graph is satisfactory.

As for the GTL stuff, I don't think there should be any excuse for SAS to let those key words to display in red color since SAS decides to let them work with SAS BASE. How can users understand why if they can't see your reply?!
Ask a Question
Discussion stats
  • 9 replies
  • 2549 views
  • 0 likes
  • 2 in conversation