I'm struggling to shrink the range of x-axis date values in an sgpanel plot. I've tried several options including using the min/max values, limiting the data set with a where statement and others. I would like the graph to start in 1Nov2015 and end at 30Sep2021. Here is my code:
proc sgpanel data=gen_enc; where fisc_monyr >= '01Nov2015'd; panelby catvar1 / layout=rowlattice onepanel novarname uniscale=column; series x=fisc_monyr y=ctsvar1 / legendlabel='xxx' lineattrs=(color=black); series x=fisc_monyr y=catvar2 / legendlabel='yyy' lineattrs=(color=crimson); band x=fisc_monyr upper=xxx=0 /transparency=0.7; colaxis grid values=('01Nov2015'd to '01Oct2021'd) valuesformat=monyy. label="Month-Year" display=all interval=year valuesrotate=diagonal notimesplit; rowaxis grid label="AAA per month"; format fisc_monyr monyy. dmisid $fomrat_gph.; /*Add refline for start date*/ refline mgen_date / axis=x label=mgen_label labelattrs=(color=black Family=arial size=6) lineattrs=(color=gray pattern=shortDash thickness=1) transparency=0.6 ; refline covid_start / axis=x label=covid_label labelattrs=(color=black Family=arial size=6) labelpos=min lineattrs=(color=black pattern=dot thickness=1) transparency=0.8 ; run;
Here is how the x-axis is showing:
Is there a way to get rid of the space in the red boxes?
Thanks!
Ben
Show your log, include the submitted code and all the notes, messages and warnings that may appear. Copy all the text and paste into a text box opened on the forum with the </> icon above the message window.
Best would be to provide some data that behaves like that.
When you use DATE values and formats and have uneven boundaries, like your Nov to Oct (not a year or calendar quarter) then the defaults to display the values can start running into multiple issues. You have about 6 years of data and the display space for the axis labels doesn't have much space. You may be able to get more control listing actual values for each tick mark, possibly:
values=('01Nov2015'd, '01Jan2016'd to '01Jan2021'd by year,'01Oct2021'd)
but SAS get get picky about uneven intervals with some display spaces.
It might help to make the size of the graph larger with the ODS Graphics Width setting.
FWIW, not personally a fan of the MONYY5 format as it is easy to confuse Day of Month with the 2-digit year on a glance with some ranges of values.
Show your log, include the submitted code and all the notes, messages and warnings that may appear. Copy all the text and paste into a text box opened on the forum with the </> icon above the message window.
Best would be to provide some data that behaves like that.
When you use DATE values and formats and have uneven boundaries, like your Nov to Oct (not a year or calendar quarter) then the defaults to display the values can start running into multiple issues. You have about 6 years of data and the display space for the axis labels doesn't have much space. You may be able to get more control listing actual values for each tick mark, possibly:
values=('01Nov2015'd, '01Jan2016'd to '01Jan2021'd by year,'01Oct2021'd)
but SAS get get picky about uneven intervals with some display spaces.
It might help to make the size of the graph larger with the ODS Graphics Width setting.
FWIW, not personally a fan of the MONYY5 format as it is easy to confuse Day of Month with the 2-digit year on a glance with some ranges of values.
I believe this is happening because the axis offsets are being calculated based on your long REFLINE labels. You can override this calculation by using the the OFFSETMIN and OFFSETMAX options on the COLAXIS statement. For example, you'll probably want to use OFFSETMIN=0 (or perhaps 0.05), since the first tick value is the only feature requiring space. For the OFFSETMAX, try the same value you use for OFFSETMIN, as the REFLINE labels all fall within the area of your series plots, leaving you only with the last tick value to include.
Hope this helps!
Dan
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.