Hi All,
I am creating a legend with PROC GCHART VAR3D, but not sure why it is not created into the final output. Please note that the ODS destination is PDF.
Is there any chance of legend getting suppressed because of any other option in the code?
Patternid simply colors the bars - if you want a legend, you'll need to use the subgroup= option rather than patternid= option (I have never really found a good use for 'patternid' - if I want bar segments to be colored I always use the subgroup option). Here is an example:
legend1 position=bottom;
proc gchart data=sashelp.class;
vbar sex / type=sum sumvar=weight patternid=midpoint legend=legend1;
run;
proc gchart data=sashelp.class;
vbar sex / type=sum sumvar=weight subgroup=sex legend=legend1;
run;
This is mentioned in the gchart documentation:
http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#gchart-bar.htm
To create a legend based on the chart midpoints
instead of the subgroups, use the chart variable as the subgroup variable:
Does your SAS log mention anything about the legend?
Hi Robert,
Below is the reference code. The log is having no info regarding the legend.
goptions ftext = "Albany AMT"
ftitle = "Albany AMT"
htext = 12pt
vsize = 6.00
hsize = 8.42
vorigin = 1.00
rotate = portrait
;
title1 'Title';
footnote;
pattern1 v=s c=yellow;
pattern2 v=s c=red;
pattern3 v=s c=green;
/* Define legend characteristics */
legend1 label=(height=1 'Category') value=(tick=1 j=c "DEPARTMENT" tick=2 j=c "RESULT" tick=3 j=c "COMMENT")
across=3 down=1 position = bottiom mode=reserve ;
axis1 label=('Value') order= (0 to 30 by 5) minor=none ;
axis2 label=none value=none;
axis3 label=none value=(a=90) ;
PROC GCHART DATA=ssu_g_t;
VBAR3D cat /
SUMVAR=count
GROUP=date
LEGEND = LEGEND1
SHAPE=BLOCK
COUTLINE=BLACK
RAXIS=AXIS1
MAXIS=AXIS2
GAXIS=AXIS3
OUTSIDE=SUM
PATTERNID=MIDPOINT
AUTOREF CREF=gray7a
;
run;
quit;
Please not that cat is a char variable and cnt is the total count per category value and date is the x axis (month/year wise).
I am getting below two warning in the log (and also inside=sum / outside= sum option also not working for PROC GCHART VAR3D):
WARNING: The intervals on the axis labeled date are not evenly spaced.
WARNING: The VBAR/VBAR3D chart for cat could not be labeled because the labels are wider than the bars.
Patternid simply colors the bars - if you want a legend, you'll need to use the subgroup= option rather than patternid= option (I have never really found a good use for 'patternid' - if I want bar segments to be colored I always use the subgroup option). Here is an example:
legend1 position=bottom;
proc gchart data=sashelp.class;
vbar sex / type=sum sumvar=weight patternid=midpoint legend=legend1;
run;
proc gchart data=sashelp.class;
vbar sex / type=sum sumvar=weight subgroup=sex legend=legend1;
run;
This is mentioned in the gchart documentation:
http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#gchart-bar.htm
To create a legend based on the chart midpoints
instead of the subgroups, use the chart variable as the subgroup variable:
Hi Robert,
Thank you!!! It worked out!!!
You need to be more specific about your syntax. Are you creating a legend statement and referencing it in the proc gchart? Did you try to change the output to html or rtf or other format?
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.