BookmarkSubscribeRSS Feed
nhankey
Calcite | Level 5

I was curious if anyone knew of a work around for SGPLOT to display when the axis isn't appropriate (i.e. there are values outside of the range specified for an axis). I know GPLOT will throw up a note in the log, which makes it easy to track down the issue, but for SGPLOT I haven't found anything similar. 

 

For example,

data test;
do z=1 to 15;
y=z;
x=z;
output;
end;
run;

proc sgplot data=test;
series x=x y=y;
yaxis min=3 max=8;
run;

axis2 order=(3 to 8 by 1);
proc gplot data=test;
plot x*y/vaxis=axis2;
run;

 

7 REPLIES 7
SuryaKiran
Meteorite | Level 14

Sometimes I prefer taking the Min and Max values form the data, especially when the data keeps on changing and can never predict then min and max.

 

proc sql;
select min(y),max(y) INTO:Min,:max
from test;
quit;

proc sgplot data=test;
series x=x y=y;
yaxis min=&min max=&max;
run;
Thanks,
Suryakiran
ballardw
Super User

@SuryaKiran wrote:

Sometimes I prefer taking the Min and Max values form the data, especially when the data keeps on changing and can never predict then min and max.

 

proc sql;
select min(y),max(y) INTO:Min,:max
from test;
quit;

proc sgplot data=test;
series x=x y=y;
yaxis min=&min max=&max;
run;

Or if the values are decimals then Floor(min(y)), ceil(max(y))

data_null__
Jade | Level 19

Get rid of the AXIS statement. 

data_null__
Jade | Level 19

Min and MAX are doing exactly what they say they do.  Don't you want VALUES

 

MAX=numeric-value

specifies the maximum data value to include in the display (the value might be adjusted by the threshold calculation).

MIN=numeric-value

specifies the minimum data value to include in the display (the value might be adjusted by the threshold calculation).

 

VALUES=(values-list ) | (“string-list” )

specifies the values for the ticks on an axis.

DanH_sas
SAS Super FREQ

And to add to data _null_'s point, you can use the VALUEHINT option to let the axis automatically extend to include data beyond the end of the VALUES bounds, but only the VALUE tick marks will be drawn.

Quentin
Super User

I also miss the warning about data existing outside of the axis range.  Would be nice to have an option to turn on such warnings for SGPLOT.  As is, it feels too easy for me to design a nice plot, and then a month or two later some outliers appear and they are completely ignored by the plot.  If I intend to subset data I will use a WHERE option on the data, not an axis range.

 

VALUESHINT is nice for preventing the loss of display of surprise outliers.  But then you lose the ability of using the VALUES statement to force an axis to be longer than the data.

 

Maybe want I want is some sort of global NOCLIP option which would ensure that data outside of axes are always displayed.  Basically I want to say "use this axis I've specified, but if there's any data outside of it extend the axis (and give me a note that the specified axis was not used)."

 

On a related note, I think I also want the ability to specify a FROM-TO-BY VALUES option that allows you to specify only FROM, or only TO, only BY, or combinations, e.g. something like:

 

values=(0 to max)
values=(0 to max by 5)
values=(min to max by 5)

Yes, I know there are plenty of macros out there that people use to generate beautiful axis ranges.  But I like when SAS does it for me. : )

 

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
data_null__
Jade | Level 19

@Quentin wrote:

Yes, I know there are plenty of macros out there that people use to generate beautiful axis ranges.  But I like when SAS does it for me. : )

 


When I want data driven control of axis generation I have used IML routine

 

CALL GSCALE (scale, x, nincr <, nicenum> <, fixed-end> ); 

What more do you need?

 

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
  • 7 replies
  • 1532 views
  • 3 likes
  • 6 in conversation