Whats the best way of controlling the x axis length when executing a proc sgplot across several iterations when using macro variables?
proc sgplot data=xxx_subj;
format vdate date7.;
title "Subject: &pt.";
band x=studyday lower=nrlow upper=nrhigh / transparency=0.6 fill nooutline name='nr' legendlabel='Normal Range' ;
series x=vdate y=xxx / x2axis markerattrs=(size=0);
yaxis offsetmin=0.1 offsetmax=0.1 display=(noline noticks) grid label='xxx';
xaxis thresholdmin=0.25 values=(&minday to &maxday) grid label='Study Day';
x2axis thresholdmin=0.25 values=(&mindate to &maxdate) label='Study Date';
run;
So in this code the xaxis and x2axis lines have the option "values=(&min to &max)". I would like to us a "by 7" increment but when i do the x axis is either truncated or elongated based on the actual values for &min and &max and I want to avoid this.
A potential answer may be to increase the value of &max to the next multiple of 7 based from the &min value. Would this be a valid way to control the axis or is there a better alternative?
According to the 9.4 help when the "by" statement is not provide "The result can be unpredictable output." which sounds not good.
Thanks for your help.
If your interval does not exactly match your date then this note from the documentation on values applies:
If the specified range is not evenly divisible by the increment value, the highest value displayed on the axis is the last incremental value below the ending value for the range. For example, this value list produces a maximum axis value of 9: values=(0 to 10 by 3)
so if that is happening you might have to accept having a value slightly larger than you want. So increment &maxday (or &minday which ever makes sense) to get the intervals to work is appropriate.
According to the 9.4 help when the "by" statement is not provide "The result can be unpredictable output." which sounds not good.
Depending on the range of values encountered most likely you would get a multiple of 10, 100, 1000 or 5, 50, 500 as an interval without specifying the BY interval. Usually not really atrocious but if you have charts that you would like to have similar intervals displayed then one with an interval of 20 and the other with 25 because the second contained one value that was 15 larger than the largest of the first might be annoying.
If your interval does not exactly match your date then this note from the documentation on values applies:
If the specified range is not evenly divisible by the increment value, the highest value displayed on the axis is the last incremental value below the ending value for the range. For example, this value list produces a maximum axis value of 9: values=(0 to 10 by 3)
so if that is happening you might have to accept having a value slightly larger than you want. So increment &maxday (or &minday which ever makes sense) to get the intervals to work is appropriate.
According to the 9.4 help when the "by" statement is not provide "The result can be unpredictable output." which sounds not good.
Depending on the range of values encountered most likely you would get a multiple of 10, 100, 1000 or 5, 50, 500 as an interval without specifying the BY interval. Usually not really atrocious but if you have charts that you would like to have similar intervals displayed then one with an interval of 20 and the other with 25 because the second contained one value that was 15 larger than the largest of the first might be annoying.
Thanks ballardw. I've added 6 to &maxdate so even though this over extends the x axis all values are now reported and not truncated.
Use VALUESHINT on the XAXIS statement. This still keeps the axis range to what comes from the data. The tick values are displayed as you specify in the VALUES option, without increasing or decreasing the axis range.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.