Contributor
Posts: 37

# Specify grid interval without specifying minimum and maximum of the axis

Hi,

Is there a way to specify grid interval without specifying the minimum and max of the axis?

For example, we typically have this for the specs of the axis:

axis1 order=(0 to 100 by 10);

But my range for the axis changes and I don't want to specify it.  But I need to specify the interval.

Is there a way to do that?

Thanks.

Jason

Super User
Posts: 13,583

## Re: Specify grid interval without specifying minimum and maximum of the axis

When I had a similar need I used to pull the max and min values of the variable, round up or down (floor and ceiling functions) as needed to multiples of the interval and had those values assigned to macro variables. Then the Axis definition would use the min and max macro variable values in the ORDER section of the Axis statement. The problem with this approach is your data may occasionally have a range large enough that for your desired interval the results are illegible or that SAS can't use such as 10 to 10000 by 10.

You might also experiment with using the MAJOR=(Number = n) to use a standard number of tick marks and let the interval fall as it may.

Contributor
Posts: 37

## Re: Specify grid interval without specifying minimum and maximum of the axis

Thanks.  I'll try that.

PROC Star
Posts: 8,169

## Re: Specify grid interval without specifying minimum and maximum of the axis

Would it suffice to include a short proc sql to get the min, max and interval into macro variables that could then be used for your axis statement?  e.g.:

data have;

input x;

cards;

1

5

9

18

26

30

;

proc sql noprint;

select min(x),max(x),round((max(x)-min(x))/10)

into :min,:max,:interval

from have

;

quit;

axis1 order=(&min. to &max. by &interval.);

Contributor
Posts: 37

Thank you.

Posts: 3,852

## Re: Specify grid interval without specifying minimum and maximum of the axis

You might consider the IML routine GSCALE which will be more powerful(option wise) and produced more pleasing results.

data have;
input x;
cards;
1
5
9
18
26
30
;

%let NINCR=4;

proc iml;

use have;
/*CALL GSCALE( scale, , nincr<, nicenum<, fixed-end>);*/

CALL GSCALE(scale,X,&nincr);
scaleT = t(scale);

call symputX('XSTART',    scale[1],'G');
call symputX('XEND',      scale[2],'G');
call symputX('XINCREMENT',scale[3],'G');
quit;
%put NOTE: &xstart TO &xend BY &XINCREMENT;
Contributor
Posts: 37