Data visualization with SAS programming

Sgplot: controlling the xaxis with macro variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Sgplot: controlling the xaxis with macro variables

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.


Accepted Solutions
Solution
‎03-10-2018 07:39 AM
Super User
Posts: 13,000

Re: Sgplot: controlling the xaxis with macro variables

 

 

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.

View solution in original post


All Replies
Solution
‎03-10-2018 07:39 AM
Super User
Posts: 13,000

Re: Sgplot: controlling the xaxis with macro variables

 

 

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.

Occasional Contributor
Posts: 14

Re: Sgplot: controlling the xaxis with macro variables

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.

 

 

SAS Super FREQ
Posts: 1,263

Re: Sgplot: controlling the xaxis with macro variables

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 168 views
  • 0 likes
  • 3 in conversation