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

When I apply VALUES and VALUESFORMAT in XAXIS, SGPLOT automatically trims some trailing observations. The left uses a naked format so displays correctly, but the right uses YEAR10 in VALUES and YEAR4. in VALUESFORMAT so ends much earlier than the left. How can I avoid this problem?

out.pngout1.png

Here's the code.

data have;
t=mdy(1,1,1900);
do until(year(t)>2018);
x+rannor(1);
output;
t=intnx("month",t,1);
end;
run;
ods listing gpath="!userprofile\desktop\";
ods graphics/reset imagename="out";
proc sgplot;
series x=t y=x;
run;
proc sgplot;
series x=t y=x;
xaxis values=("1jan1900"d to "1jan2019"d by year10) valuesformat=year4.;
run;
quit;

Thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Try adding the VALUESHINT option to the XAXIS. This should make the VALUES option place the ticks correctly without constraining the axis range.

 

Hope this helps!
Dan

View solution in original post

3 REPLIES 3
Reeza
Super User

Your interval is uneven, what happens if it ends at 2020, not 2019 as indicated in your specification?

 

xaxis values=("1jan1900"d to "1jan2019"d by year10) valuesformat=year4.;

My guess is because it's not a full interval it cuts off at the last 10 interval, instead of going past as the default behaviour. 

 

From the documentation:

 

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)

@Junyong wrote:

When I apply VALUES and VALUESFORMAT in XAXIS, SGPLOT automatically trims some trailing observations. The left uses a naked format so displays correctly, but the right uses YEAR10 in VALUES and YEAR4. in VALUESFORMAT so ends much earlier than the left. How can I avoid this problem?

out.pngout1.png

Here's the code.

data have;
t=mdy(1,1,1900);
do until(year(t)>2018);
x+rannor(1);
output;
t=intnx("month",t,1);
end;
run;
ods listing gpath="!userprofile\desktop\";
ods graphics/reset imagename="out";
proc sgplot;
series x=t y=x;
run;
proc sgplot;
series x=t y=x;
xaxis values=("1jan1900"d to "1jan2019"d by year10) valuesformat=year4.;
run;
quit;

Thanks for your help.


 

DanH_sas
SAS Super FREQ

Try adding the VALUESHINT option to the XAXIS. This should make the VALUES option place the ticks correctly without constraining the axis range.

 

Hope this helps!
Dan

ballardw
Super User

Any values list will "trim the data" if the limits are less than the range of the values.

It is actually a useful feature as you can quickly modify the amount of data displayed as needed.

 

Such as

proc sgplot;
series x=t y=x;
xaxis values=(-1750 -600 0 380 1800);
run;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 497 views
  • 4 likes
  • 4 in conversation