Data visualization with SAS programming

What should I do when I do not want the axis should not be drawn to scale

Reply
Occasional Contributor
Posts: 17

What should I do when I do not want the axis should not be drawn to scale

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
Occasional Contributor
Posts: 17

Re: What should I do when I do not want the axis should not be drawn to scale

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"
Regular Contributor
Posts: 165

Re: What should I do when I do not want the axis should not be drawn to scale

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.
SAS Employee
Posts: 977

Re: What should I do when I do not want the axis should not be drawn to scale

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;
Respected Advisor
Posts: 3,786

Re: What should I do when I do not want the axis should not be drawn to scale

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]
Super Contributor
Posts: 291

Re: What should I do when I do not want the axis should not be drawn to scale

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?
SAS Super FREQ
Posts: 925

Re: What should I do when I do not want the axis should not be drawn to scale

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
Occasional Contributor
Posts: 17

Re: What should I do when I do not want the axis should not be drawn to scale

Thanks a lot everyone. I too changed it to character and it worked as I wanted. Thanks for the help.
Ask a Question
Discussion stats
  • 7 replies
  • 207 views
  • 0 likes
  • 6 in conversation