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;
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;
@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))
Get rid of the AXIS statement.
Min and MAX are doing exactly what they say they do. Don't you want VALUES
specifies the maximum data value to include in the display (the value might be adjusted by the threshold calculation).
specifies the minimum data value to include in the display (the value might be adjusted by the threshold calculation).
specifies the values for the ticks on an axis.
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.
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. : )
@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?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.