turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- What should I do when I do not want the axis shoul...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-23-2010 10:28 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-23-2010 10:29 AM

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"

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-23-2010 10:50 AM

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.

Annotated data sets would probably be better but I don't know much about how to use them.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-23-2010 11:25 AM

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 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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-23-2010 01:35 PM

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]

[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]

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-23-2010 04:00 PM

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?

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-23-2010 12:36 PM

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

proc sgplot data=whatever;

xaxis type=discrete;

series x=numvar1 y=numvar2;

run;

--Dan

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-23-2010 01:45 PM

Thanks a lot everyone. I too changed it to character and it worked as I wanted. Thanks for the help.