BookmarkSubscribeRSS Feed
Reeza
Super User

Hi All,

In GCHART or GPLOT is there a way to format the axis to be integers?

Ie my points are (1.2, 10.3) (2.4,11.3) (8.5, 9.2)

I'd the like the graph axis to be 1 2 3 ... 10 rather than 1.0 to 10.0

I'm using annotate to label certain points but when I include a format statement in the gchart the annotate variables are also losing their decimal point.

Thanks.

8 REPLIES 8
art297
Opal | Level 21

Would the method described at http://communities.sas.com/message/26127#26127 suffice?

Reeza
Super User

I don't think so...because format 8. changes the annotate values it will change the values being labelled as well, and that's not what I'm looking for.

I need to label points and separately label the axis with specific values.

I see that this is the GTL for 9.3 but I haven't been able to find anything related to GPLOT or GCHART.

Thanks though!

GraphGuy
Meteorite | Level 14

I'm not sure I understand the question exactly, but you can control the format of the values used on the gplot axis tickmarks (and the gchart response axis) by applying a format - either to the data set, or specify it in the gplot.

And when annotating text values, the annotated text will be whatever you stuff into the 'text' variable - if you apply a format (such as using the put() function when you create the text variable) then the annotated text will be formatted in that way.

Here is an example:

data foo;
input x y;
datalines;
1.2 10.3
2.4 11.3
8.5 9.2
;
run;

data foo_anno; set foo;
function='label'; position='2'; xsys='2'; ysys='2'; color='red';
text=put(y,comma5.0);
run;

proc gplot data=foo anno=foo_anno;
format y comma5.0;
format x comma5.0;
plot y*x;
run;

Reeza
Super User

Thanks Rob,

I was mistaken, the labels are being output by a symbol and pointlabel statement rather than annotate, the annotate is used for something else.

Is there a way to format to apply specific formats using the symbol or axis statement?

GraphGuy
Meteorite | Level 14

Well, for the axes, I would definitely use the format in the data, or the format in the proc gplot, to control the format of the numbers in the axes.

To get the maximum flexibility in the pointlabel, I could create a new text variable in the data set (similar to the one I created in the annotate data set), and use the put() function and whatever format you like (and even add extra characters if desired), and then specify that as the variable to use as the pointlabel.


data foo;
input x y;
text=put(y,comma5.0);
datalines;
1.2 10.3
2.4 11.3
8.5 9.2
;
run;

symbol value=dot height=2 color=red
     pointlabel=("#text" h=2.2 c=gray55 font="albany amt/bold");

proc gplot data=foo;
format y comma5.0;
format x comma5.0;
plot y*x;
run;

Reeza
Super User

The following seems to give me what I want the easiest.

data foo;

input x y;

datalines;

1.2 10.3

2.4 11.3

8.5 9.2

;

run;

data foo_anno; set foo;

function='label'; position='2'; xsys='2'; ysys='2'; color='red';

text=put(y,comma5.1);

run;

axis1 value=('1' '2' '3' '4' '5' '6' '7' '8' '9' '10');

proc gplot data=foo anno=foo_anno;

plot y*x/haxis=axis1;

run;

Rob's solution is probably more maintainable, but this is a quick fix at the moment.

Thanks!

GraphGuy
Meteorite | Level 14

This quick-fix (hard-coding values in the axis statement) is pretty dangerous, especially since you're letting the axis auto-scale -- if the data you're plotting ever changes (and causes the axis to auto-scale another way, say from 1 to 5), then these hard-coded axis values would become wrong.

Reeza
Super User

Thanks for the heads up.

I also didn't mark my own answer as correct, instead I said assumed answered :smileyconfused:

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 8 replies
  • 5191 views
  • 6 likes
  • 3 in conversation