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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

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

  • The PATTERNID= option is set to any value other than
    SUBGROUP; that is, the value of PATTERNID= is BY or GROUP or
    MIDPOINT.

      To create a legend based on the chart midpoints
     instead of the subgroups, use the chart variable as the subgroup variable:

View solution in original post

5 REPLIES 5
GraphGuy
Meteorite | Level 14

Does your SAS log mention anything about the legend?

alwaz_searching
Calcite | Level 5

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.

GraphGuy
Meteorite | Level 14

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

  • The PATTERNID= option is set to any value other than
    SUBGROUP; that is, the value of PATTERNID= is BY or GROUP or
    MIDPOINT.

      To create a legend based on the chart midpoints
     instead of the subgroups, use the chart variable as the subgroup variable:

alwaz_searching
Calcite | Level 5

Hi Robert,

Thank you!!! It worked out!!! Smiley Happy

Dorota_Jarosz
Obsidian | Level 7

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?

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
  • 5 replies
  • 2790 views
  • 0 likes
  • 3 in conversation