Hello,
I have the following code, however, could not figure out how to improve it in order to get the graph as attached. Thank you so much!
goptions reset=all cback=white border htitle=12pt htext=10pt;
data ds1;
input year $ mid $ resp exp rev;
datalines;
null d_2016 0.45 0.45 0.35
null d_2015 0.35 0.45 0.35
s_300 d_2016 0.65 0.65 0.55
s_300 d_2015 0.55 0.65 0.55
s_640 d_2016 0.42 0.42 0.65
s_640 d_2015 0.65 0.42 0.65
s_670 d_2016 0.35 0.35 0.75
s_670 d_2015 0.75 0.35 0.75
s_700 d_2016 0.83 0.83 0.47
s_700 d_2015 0.47 0.83 0.47
s_730 d_2016 0.48 0.48 0.58
s_730 d_2015 0.58 0.48 0.58
s_760 d_2016 0.67 0.67 0.69
s_760 d_2015 0.69 0.67 0.69
;
run;
data ds2;
set ds1;
n=_n_;
run;
data _null_;
set ds2 end=eof;
if eof then call symput('skip',left(n));
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=+2; 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=+2; 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=3; y=13; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='"Albany AMT"'; text='d_2015'; color='black';
x=6; y=13; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='marker'; text='U'; color='cxde7e6f';
x=3; y=8.5; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='"Albany AMT"'; text='d_2016'; color='black';
x=6; 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=+8; 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 'Score distribution';
axis1 label=(a=90 'Percentegy')
order=(0 to 1 by 0.1)
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=0 width=5
cframe=ltgray autoref clipref
raxis=axis1 maxis=axis2 gaxis=axis3
annotate=anno;
run;
quit;
ods graphics / reset width=5in height=3in attrpriority=color;
title 'Overall Distribution';
proc sgplot data=ds1 noborder noautolegend;
styleattrs wallcolor=cxf0f0f0;
vbarparm category=year response=resp / group=mid groupdisplay=cluster
clusterwidth=0.6 outlineattrs=(color=black)
baselineattrs=(thickness=0);
series x=year y=exp / group=mid lineattrs=(color=gold thickness=2) y2axis;
series x=year y=rev / group=mid lineattrs=(color=green thickness=2) y2axis;
xaxistable resp / class=mid colorgroup=mid;
xaxis display=(noline noticks nolabel) ;
yaxis display=(noline noticks) grid gridattrs=(color=white thickness=1) offsetmin=0;
y2axis display=(noline noticks) min=0;
run;
No graph attached...
Hello,
I have the following code, however, could not figure out how to improve it in order to get the graph as attached. Thank you so much!
goptions reset=all cback=white border htitle=12pt htext=10pt;
data ds1;
input year $ mid $ resp exp rev;
datalines;
null d_2016 0.45 0.45 0.35
null d_2015 0.35 0.45 0.35
s_300 d_2016 0.65 0.65 0.55
s_300 d_2015 0.55 0.65 0.55
s_640 d_2016 0.42 0.42 0.65
s_640 d_2015 0.65 0.42 0.65
s_670 d_2016 0.35 0.35 0.75
s_670 d_2015 0.75 0.35 0.75
s_700 d_2016 0.83 0.83 0.47
s_700 d_2015 0.47 0.83 0.47
s_730 d_2016 0.48 0.48 0.58
s_730 d_2015 0.58 0.48 0.58
s_760 d_2016 0.67 0.67 0.69
s_760 d_2015 0.69 0.67 0.69
;
run;
data ds2;
set ds1;
n=_n_;
run;
data _null_;
set ds2 end=eof;
if eof then call symput('skip',left(n));
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=+2; 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=+2; 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=3; y=13; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='"Albany AMT"'; text='d_2015'; color='black';
x=6; y=13; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='marker'; text='U'; color='cxde7e6f';
x=3; y=8.5; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='"Albany AMT"'; text='d_2016'; color='black';
x=6; 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=+8; 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 'Score distribution';
axis1 label=(a=90 'Percentegy')
order=(0 to 1 by 0.1)
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=0 width=5
cframe=ltgray autoref clipref
raxis=axis1 maxis=axis2 gaxis=axis3
annotate=anno;
run;
quit;
ods graphics / reset width=5in height=3in attrpriority=color;
title 'Overall Distribution';
proc sgplot data=ds1 noborder noautolegend;
styleattrs wallcolor=cxf0f0f0;
vbarparm category=year response=resp / group=mid groupdisplay=cluster
clusterwidth=0.6 outlineattrs=(color=black)
baselineattrs=(thickness=0);
series x=year y=exp / group=mid lineattrs=(color=gold thickness=2) y2axis;
series x=year y=rev / group=mid lineattrs=(color=green thickness=2) y2axis;
xaxistable resp / class=mid colorgroup=mid;
xaxis display=(noline noticks nolabel) ;
yaxis display=(noline noticks) grid gridattrs=(color=white thickness=1) offsetmin=0;
y2axis display=(noline noticks) min=0;
run;
Since you have SAS 9.4, you can use AxisTable as shown here to create your graph:
http://blogs.sas.com/content/graphicallyspeaking/2016/07/17/graph-table-with-class/
Hello,
I have the following code, however, could not figure out how to improve it in order to get the graph as attached. Thank you so much!
goptions reset=all cback=white border htitle=12pt htext=10pt;
data ds1;
input year $ mid $ resp exp rev;
datalines;
null d_2016 0.45 0.45 0.35
null d_2015 0.35 0.45 0.35
s_300 d_2016 0.65 0.65 0.55
s_300 d_2015 0.55 0.65 0.55
s_640 d_2016 0.42 0.42 0.65
s_640 d_2015 0.65 0.42 0.65
s_670 d_2016 0.35 0.35 0.75
s_670 d_2015 0.75 0.35 0.75
s_700 d_2016 0.83 0.83 0.47
s_700 d_2015 0.47 0.83 0.47
s_730 d_2016 0.48 0.48 0.58
s_730 d_2015 0.58 0.48 0.58
s_760 d_2016 0.67 0.67 0.69
s_760 d_2015 0.69 0.67 0.69
;
run;
data ds2;
set ds1;
n=_n_;
run;
data _null_;
set ds2 end=eof;
if eof then call symput('skip',left(n));
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=+2; 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=+2; 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=3; y=13; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='"Albany AMT"'; text='d_2015'; color='black';
x=6; y=13; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='marker'; text='U'; color='cxde7e6f';
x=3; y=8.5; position='6';
output;
function='label'; xsys='3'; ysys='3';
style='"Albany AMT"'; text='d_2016'; color='black';
x=6; 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=+8; 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 'Score distribution';
axis1 label=(a=90 'Percentegy')
order=(0 to 1 by 0.1)
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=0 width=5
cframe=ltgray autoref clipref
raxis=axis1 maxis=axis2 gaxis=axis3
annotate=anno;
run;
quit;
ods graphics / reset width=5in height=3in attrpriority=color;
title 'Overall Distribution';
proc sgplot data=ds1 noborder noautolegend;
styleattrs wallcolor=cxf0f0f0;
vbarparm category=year response=resp / group=mid groupdisplay=cluster
clusterwidth=0.6 outlineattrs=(color=black)
baselineattrs=(thickness=0);
series x=year y=exp / group=mid lineattrs=(color=gold thickness=2) y2axis;
series x=year y=rev / group=mid lineattrs=(color=green thickness=2) y2axis;
xaxistable resp / class=mid colorgroup=mid;
xaxis display=(noline noticks nolabel) ;
yaxis display=(noline noticks) grid gridattrs=(color=white thickness=1) offsetmin=0;
y2axis display=(noline noticks) min=0;
run;
Have a look at this blog:
http://blogs.sas.com/content/graphicallyspeaking/
Has many examples of graphs. Am not sure why you have all the code there, just get your data correct and in a good strcuture, and it should all be possble in one sgplot statement.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.