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

Hi all,

I am using sas code I found to generate every month graph. Problem showed up this month with new month

"ERROR: The bottom horizontal axis labeled "year_month" could not be fit. There was not enough room in the graph's display area to
fit the group axis."

Where should I start changing this code? 

Attached last month graph.

 

for table 

year_monthintcon
2019/0985
2019/10167
2019/112511
2019/122717
2020/013622
2020/024727
2020/034728

 

 

 

data edanno;
set hfedroll1;
by year_month mid;
length function color $8 text $20 style $ 20;

/* Populate the table */
if first.year_month then do;
function='move'; xsys='2'; ysys='1';
midpoint=mid; group=year_month; y=0;
output;
function='cntl2txt'; output;
function='label'; xsys='A'; ysys='3';
x=+4; y=13;
text=trim(left(put(int,8.)));
color='black'; position='+'; when='a';
output;
function='move'; xsys='2'; ysys='1';
midpoint=mid; group=year_month; y=0;
output;
function='cntl2txt'; output;
function='label'; xsys='A'; ysys='3';
x=+4; y=9;
text=trim(left(put(con,8.)));
color='black'; position='+'; when='a';
output;
end;

/* Generate the table frame */
function='move'; xsys='3'; ysys='3';
x=3; y=6;
output;
function='bar'; xsys='1'; ysys='3';
x=100; y=15;
style='empty'; color='black'; line=0;
output;

/* Generate the row headers */
function='label'; xsys='3'; ysys='3';
style='marker'; text='U'; color='cx7c95ca';
x=4; y=13; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='"Albany AMT"'; text='Intervention'; color='black';
x=7; y=13; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='marker'; text='U'; color='cxde7e6f';
x=4; y=8.5; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='"Albany AMT"'; text='Control'; color='black';
x=7; y=9; position='6';
output;

/* Generate the vertical lines in the table */
function='move'; xsys='1'; ysys='1';
x=0; y=0;
output;
function='draw'; xsys='1'; ysys='3';
x=0; y=6;
line=1; color='black';
output;
function='move'; xsys='1'; ysys='1';
x=100; y=0;
output;
function='draw'; xsys='1'; ysys='3';
x=100; y=6;
line=1; color='black';
output;

if first.year_month and n ^=&skip then do;
function='move'; xsys='2'; ysys='1';
midpoint=mid; y=0; group=year_month;
output;
function='move'; xsys='A'; ysys='1';
x=+15.5; x=+12; y=0;
output;
function='draw'; xsys='A'; ysys='3';
x=+0; y=6;
color='black'; line=1;
output;
end;

/* Generate the horizontal line in the table */
function='move'; xsys='3'; ysys='3';
x=3; y=10.5;
output;
function='draw'; xsys='1'; ysys='3';
x=100; y=10.5;
line=1; color='black';
output;
run;



axis1 label=(a=90 'Nr of encounters')
order=(0 to 100 by 10)
minor=none;

axis2 label=none
value=none
origin=(20pct,22pct)

offset=(4pct,4pct);

axis3 label=none;

footnote1 'year_month';
footnote2 h=.5 ' ';

pattern1 value=solid color=cx7c95ca;
pattern2 value=solid color=cxde7e6f;

 

proc gchart data=hfedroll1;
vbar mid / sumvar=resp group=year_month
coutline=black patternid=midpoint
space=0 gspace=5 width=4
cframe=ltgray autoref clipref
raxis=axis1 maxis=axis2 gaxis=axis3
annotate=edanno;
run;
quit;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

I think it might be possible to use the SG procedures to do this, which would completely eliminate the fussy coding, and might be doable in about a dozen lines.

 

Here's a link to a somewhat similar situation, I hope it helps to give you ideas.

 

https://blogs.sas.com/content/graphicallyspeaking/2018/02/19/survival-plot-twist-using-sgplot-proced... 

 

Tom

View solution in original post

4 REPLIES 4
Mark7
Obsidian | Level 7

Below original sas code. Without 2001/03 and 2001/04 works proper

 

/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;

data ds1;
input year $ exp rev;
datalines;
1997/98 302.3 310.8
1998/99 323.0 328.7
1999/00 354.4 363.5
2000/01 381.7 390.2
2001/02 426.8 429.1
2001/03 481.7 490.2
2001/04 498.8 498.1


;
run;

data ds2;
set ds1;
n=_n_;
run;

data _null_;
set ds2 end=eof;
if eof then call symput('skip',left(n));
run;

data ds2;
set ds2;
resp=exp; mid='exp'; output;
resp=rev; mid='rev'; output;
run;

proc sort;
by year mid;
run;

data anno;
set ds2;
by year mid;
length function color $8 text $20 style $ 20;

/* Populate the table */
if first.year then do;
function='move'; xsys='2'; ysys='1';
midpoint=mid; group=year; y=0;
output;
function='cntl2txt'; output;
function='label'; xsys='A'; ysys='3';
x=+4; y=13;
text=trim(left(put(exp,8.1)));
color='black'; position='+'; when='a';
output;
function='move'; xsys='2'; ysys='1';
midpoint=mid; group=year; y=0;
output;
function='cntl2txt'; output;
function='label'; xsys='A'; ysys='3';
x=+4; y=9;
text=trim(left(put(rev,8.1)));
color='black'; position='+'; when='a';
output;
end;

/* Generate the table frame */
function='move'; xsys='3'; ysys='3';
x=3; y=6;
output;
function='bar'; xsys='1'; ysys='3';
x=100; y=15;
style='empty'; color='black'; line=0;
output;

/* Generate the row headers */
function='label'; xsys='3'; ysys='3';
style='marker'; text='U'; color='cx7c95ca';
x=4; y=13; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='"Albany AMT"'; text='Expenditure'; color='black';
x=7; y=13; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='marker'; text='U'; color='cxde7e6f';
x=4; y=8.5; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='"Albany AMT"'; text='Revenue'; color='black';
x=7; y=9; position='6';
output;

/* Generate the vertical lines in the table */
function='move'; xsys='1'; ysys='1';
x=0; y=0;
output;
function='draw'; xsys='1'; ysys='3';
x=0; y=6;
line=1; color='black';
output;
function='move'; xsys='1'; ysys='1';
x=100; y=0;
output;
function='draw'; xsys='1'; ysys='3';
x=100; y=6;
line=1; color='black';
output;

if first.year and n ^=&skip then do;
function='move'; xsys='2'; ysys='1';
midpoint=mid; y=0; group=year;
output;
function='move'; xsys='A'; ysys='1';
x=+15.5; x=+12; y=0;
output;
function='draw'; xsys='A'; ysys='3';
x=+0; y=6;
color='black'; line=1;
output;
end;

/* Generate the horizontal line in the table */
function='move'; xsys='3'; ysys='3';
x=3; y=10.5;
output;
function='draw'; xsys='1'; ysys='3';
x=100; y=10.5;
line=1; color='black';
output;
run;

title1 'Revenue and Expenditures, 1997/98-2001-02';

axis1 label=(a=90 'Millions of Dollars')
order=(100 to 450 by 50)
minor=none;

axis2 label=none
value=none
origin=(20pct,22pct)
offset=(4pct,4pct);

axis3 label=none;

footnote1 'Fiscal Year';
footnote2 h=.5 ' ';

pattern1 value=solid color=cx7c95ca;
pattern2 value=solid color=cxde7e6f;

proc gchart data=ds2;
vbar mid / sumvar=resp group=year
coutline=black patternid=midpoint
space=0 gspace=5 width=4
cframe=ltgray autoref clipref
raxis=axis1 maxis=axis2 gaxis=axis3
annotate=anno;
run;
quit;

TomKari
Onyx | Level 15

I think it might be possible to use the SG procedures to do this, which would completely eliminate the fussy coding, and might be doable in about a dozen lines.

 

Here's a link to a somewhat similar situation, I hope it helps to give you ideas.

 

https://blogs.sas.com/content/graphicallyspeaking/2018/02/19/survival-plot-twist-using-sgplot-proced... 

 

Tom

Mark7
Obsidian | Level 7

Thank you TomKari. I will start digging code from your blog.

ballardw
Super User

Depending on the actual number of elements in your group axis you could try adding to the group axis definition

 

1) Split = '/' which would use your / to split the year and month components to separate lines in the label so you got something like

 

2019

  09 

in appearance

 

2) add an option such as ANGLE =45 on the AXIS statement for the VALUES used by the group variable to have the text appear at an angle so the overall width used by the label is less, if you go to Angle=90 (or -90) you get vertical text

 

3) use shorter text for the value or display using a smaller font, again modify the Axis font size to something smaller

 

4) make the graph display in a larger area

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1263 views
  • 2 likes
  • 3 in conversation