BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mikey03
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

 

 

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

3 REPLIES 3
ballardw
Super User

 

 

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.

Mikey03
Obsidian | Level 7

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.

 

 

Jay54
Meteorite | Level 14

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-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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
  • 3 replies
  • 1196 views
  • 0 likes
  • 3 in conversation