BookmarkSubscribeRSS Feed
JasonL
Quartz | Level 8

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

6 REPLIES 6
ballardw
Super User

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.

art297
Opal | Level 21

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

data_null__
Jade | Level 19

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;
   read all into X;
   /*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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 6 replies
  • 591 views
  • 0 likes
  • 4 in conversation