BookmarkSubscribeRSS Feed
Fisher
Quartz | Level 8
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.
9 REPLIES 9
DanH_sas
SAS Super FREQ
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
Fisher
Quartz | Level 8
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
DanH_sas
SAS Super FREQ
Inside of the yaxisopts=(), add this:

linearopts=(tickvalueformat=)

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

barlabelattrs=(size=12pt)

-- Dan
Fisher
Quartz | Level 8
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;
DanH_sas
SAS Super FREQ
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
Fisher
Quartz | Level 8
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.
DanH_sas
SAS Super FREQ
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
DanH_sas
SAS Super FREQ
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
Fisher
Quartz | Level 8
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?!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 8413 views
  • 0 likes
  • 2 in conversation