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

Hello!

My shortened sgplot-Syntax is like

vbar  week / response=blood_donation group=Product nomissinggroup;
vline week / response=blood_issued group=Product nomissinggroup;

and I have to exclude observations with missing values for the group variable to have a nice legend. Nomissinggroup doesn't seem to work in that way.

Is there a simple way to exclude missing value groups?

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hallo @AntjeWestphal,

 

How about this legend?

keylegend.png

Obtained with this code:

proc sgplot data=Ges;
title height=15pt 'Pool-TK und Apherese-TK';
  xaxis labelattrs=(size=15);
  yaxis label='TK-Herstellung und -Abgabe an Patienten' values=(0 to 100 by 10) offsetmin=0 valueattrs=(size=13) labelattrs=(size=15);
  y2axis label='VB-Spenden' values=(0 to 400 by 40) offsetmin=0 valueattrs=(size=13) labelattrs=(size=15);
  vbar KW2 / name='B1' response=Herst group=Produkt transparency=0.2;
  vline KW2 / name='LP' response=AusgTK group=Produkt lineattrs=(thickness=2);
  vbar KW2 / name='B2' response=SpendVB group=Produkt transparency=0.4 nooutline barwidth=0.4 fillattrs=(color=grey) y2axis;
  keylegend 'B1' / noborder valueattrs=(size=12) exclude=('TK'             'VB') position=bottomleft;
  keylegend 'LP' / noborder valueattrs=(size=12) exclude=(     'TKP' 'TKZ' 'VB') position=bottom;
  keylegend 'B2' / noborder valueattrs=(size=12) exclude=('TK' 'TKP' 'TKZ'     ) position=bottomright;
run;

I added the NAME= option to the plots and separate KEYLEGEND statements for each plot, referring to the (arbitrary) names, using the EXCLUDE= option to remove the unwanted items and the POSITION= option for the positioning. Moreover, I omitted the LEGENDLABEL= options because they have "no effect if you also specify the GROUP= option in the same plot statement" (according to the documentation).

View solution in original post

8 REPLIES 8
Reeza
Super User
Usually missing values are excluded by default, can you provide an example of how your missing is shown.
maguiremq
SAS Super FREQ

Could you add a statement like this after the `VBAR` and `VLINE`?

 

where product ~= "";

Assuming `product` is a character variable.

acordes
Rhodochrosite | Level 12
Try suppressing at first one of the 2 plots. To see how it behaves for only one plot. Perhaps nonmissinggroups are not consistent for both response variables.
AntjeWestphal
Obsidian | Level 7

Here are the data. It's a mixture out of 3 different sources.

AntjeWestphal
Obsidian | Level 7

This is the original code:

proc sgplot data=Ges;
title height=15pt 'Pool-TK und Apherese-TK';
  xaxis labelattrs=(size=15);
  yaxis label='TK-Herstellung und -Abgabe an Patienten' values=(0 to 100 by 10) offsetmin=0 valueattrs=(size=13) labelattrs=(size=15);
  y2axis label='VB-Spenden' values=(0 to 400 by 40) offsetmin=0 valueattrs=(size=13) labelattrs=(size=15);
  vbar KW2 / response=Herst group=Produkt transparency=0.2 legendlabel='Herstellung';
  vline KW2 / response=AusgTK group=Produkt lineattrs=(thickness=2) legendlabel='TK-Ausgaben';
  vbar KW2 / response=SpendVB group=Produkt transparency=0.4 nooutline legendlabel='VB-Spenden' barwidth=0.4 fillattrs=(color=grey) y2axis;
  keylegend / noborder valueattrs=(size=12);
run;
AntjeWestphal
Obsidian | Level 7

And here is the result. The graphs are nice but not the legend. (Please disregard the color selection. 😉)

FreelanceReinh
Jade | Level 19

Hallo @AntjeWestphal,

 

How about this legend?

keylegend.png

Obtained with this code:

proc sgplot data=Ges;
title height=15pt 'Pool-TK und Apherese-TK';
  xaxis labelattrs=(size=15);
  yaxis label='TK-Herstellung und -Abgabe an Patienten' values=(0 to 100 by 10) offsetmin=0 valueattrs=(size=13) labelattrs=(size=15);
  y2axis label='VB-Spenden' values=(0 to 400 by 40) offsetmin=0 valueattrs=(size=13) labelattrs=(size=15);
  vbar KW2 / name='B1' response=Herst group=Produkt transparency=0.2;
  vline KW2 / name='LP' response=AusgTK group=Produkt lineattrs=(thickness=2);
  vbar KW2 / name='B2' response=SpendVB group=Produkt transparency=0.4 nooutline barwidth=0.4 fillattrs=(color=grey) y2axis;
  keylegend 'B1' / noborder valueattrs=(size=12) exclude=('TK'             'VB') position=bottomleft;
  keylegend 'LP' / noborder valueattrs=(size=12) exclude=(     'TKP' 'TKZ' 'VB') position=bottom;
  keylegend 'B2' / noborder valueattrs=(size=12) exclude=('TK' 'TKP' 'TKZ'     ) position=bottomright;
run;

I added the NAME= option to the plots and separate KEYLEGEND statements for each plot, referring to the (arbitrary) names, using the EXCLUDE= option to remove the unwanted items and the POSITION= option for the positioning. Moreover, I omitted the LEGENDLABEL= options because they have "no effect if you also specify the GROUP= option in the same plot statement" (according to the documentation).

AntjeWestphal
Obsidian | Level 7

Hi Reinhard, perfect, that works great! Thanks a lot!

 

Also thanks to the other answerers!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 8 replies
  • 1678 views
  • 4 likes
  • 5 in conversation