BookmarkSubscribeRSS Feed
Soha
Calcite | Level 5
Hi,

I am a new user to SAS/GRAPH. I have a requirement where I need to plot variables X and variable Y. The values in variable X are something like 400, 92345, 96457, 97876, 99876, 100456 etc etc..... Now when I use the normal SAS code the horizontal x axis is drawn to scale i.e I get a huge space between the first datapoint and the 2nd datapoint and the remaining datapoints are very close to each other. I need the chart in such a way that only the values of the datapoints are plotted and all of them are equally spaced ( Just like how we get when using Excel spreadhseet). Any help will be greatly apperciated.

Thanks
Sohail
7 REPLIES 7
Soha
Calcite | Level 5
Sorry about the confusing Subject line. It should read "What should I do when I do not want the axis to be drawn to scale"
RickM
Fluorite | Level 6
You could do something like creating an index variable that goes from 1 to n to replace x and then in an axis statement use the value= option to specify the major tick marks as the actual x-values. This is a bit tedious and involves a bit of hard coding but if the data set is relatively small and this is a one time graph it may be a good enough quick fix.

Annotated data sets would probably be better but I don't know much about how to use them.
GraphGuy
Meteorite | Level 14
Here's a slight variation of what RickM was suggesting - except rather than hard-coding all the axis values, I create a data-driven user-defined format (on-the-fly). Hard-coding all the values is a bit cumbersome, and if your data changes then the hard-coded values are incorrect, which could compromise the data integrity of the graph.

data a;
input x y;
datalines;
400 2
92345 3
96457 2
97876 4
99876 3
100456 3
;
run;

data a; set a;
data_order=_n_;
run;

data control; set a (rename = ( data_order=start x=label));
fmtname = 'my_fmt';
type = 'N';
end = START;
run;
proc format lib=work cntlin=control;
run;

symbol1 value=dot height=3 interpol=join color=red;

axis1 minor=none offset=(3,3);
axis2 label=('X') minor=none offset=(3,3);

proc gplot data=a;
format data_order my_fmt.;
plot y*data_order / vaxis=axis1 haxis=axis2;
run;
data_null__
Jade | Level 19
A simpler method for those of use with no access to the SG procs, would be to make X a character. Notice that numeric format COMMA is right justified so values have the correct order.

[pre]
data a;
input x y;
cx = put(x,comma10.);
datalines;
400 2
92345 3
96457 2
97876 4
99876 3
100456 3
;
run;

proc gplot;
plot y * cx;
run;
quit;
[/pre]
Bill
Quartz | Level 8
Robert;

A nice trick, but a problem graph results. The integrity of the x axis is compromised - in the same way as when bars don't start at zero. I'm not a proponent of a broken scale, but this might be a use for one. Either that or leave out the 400 point and just post a note about it. And then the most important question - is this even the correct display mechanism for the data at hand?
DanH_sas
SAS Super FREQ
If you are using SAS 9.2, another option is to use PROC SGPLOT and set the axis type to be discrete:

proc sgplot data=whatever;
xaxis type=discrete;
series x=numvar1 y=numvar2;
run;

--Dan
Soha
Calcite | Level 5
Thanks a lot everyone. I too changed it to character and it worked as I wanted. Thanks for the help.
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
  • 7 replies
  • 2193 views
  • 0 likes
  • 6 in conversation