BookmarkSubscribeRSS Feed
Eva
Quartz | Level 8 Eva
Quartz | Level 8
Dear all,

I use a proc gbarline which is a really good thing. Now I'd like to have a legend for the bar and the plot - just to tell the user what the bars and what the plot displays. Putting legend=legend1 behind the sumvar unfortunately doesn't work. Does anybody know how to do this?

Best regards
Eva
9 REPLIES 9
Andre
Obsidian | Level 7
Eva,
Show perhaps some code

Andre
Eva
Quartz | Level 8 Eva
Quartz | Level 8
symbol1 value=dot height=5 interpol=join color=red width=2;

proc gbarline data=work.mygraph;

format wert percent10.2
q_aggregat percent10.2;

by mybyfield;

bar mydate / sumvar = wert discrete
raxis=axis1 maxis=axis2
ref= 0.95
cref = orange;

plot / sumvar = q_aggregat
raxis=axis3;

axis1 label=none order=(0 to 1 by 0.1);
axis2 label=none;
axis3 label=none order=(0 to 1 by 0.1);

title "#byval(mybyfield)";

run;
GraphGuy
Meteorite | Level 14
Do you have any sample data you could provide, to go along with the sample code?
Eva
Quartz | Level 8 Eva
Quartz | Level 8
Obs q_aggregat mybyfield mydate wert
1 0.20930 2 10.09.2009 0.93528
2 0.21538 2 11.09.2009 0.98630
3 0.22137 2 14.09.2009 100.000
4 0.22727 2 15.09.2009 100.000
5 0.23308 2 16.09.2009 100.000
6 0.23881 2 17.09.2009 0.98230
7 0.33544 4 10.09.2009 0.98565
8 0.33962 4 11.09.2009 0.98898
9 0.33750 4 14.09.2009 0.88032
10 0.33540 4 15.09.2009 0.94600
11 0.33333 4 16.09.2009 0.73171
12 0.33129 4 17.09.2009 0.73291
13 0.77108 5 10.09.2009 100.000
14 0.77246 5 11.09.2009 0.98247
15 0.77381 5 14.09.2009 0.99673
16 0.77515 5 15.09.2009 0.99151
17 0.77059 5 16.09.2009 0.94867
18 0.77193 5 17.09.2009 100.000
19 0.51515 6 10.09.2009 0.96884
20 0.51807 6 11.09.2009 0.95833
21 0.52096 6 14.09.2009 0.95600
22 0.52381 6 15.09.2009 0.96962
23 0.52071 6 16.09.2009 0.93400
24 0.51765 6 17.09.2009 0.82052
25 0.89404 7 10.09.2009 0.45791
26 0.89474 7 11.09.2009 0.95247
27 0.88889 7 14.09.2009 0.87443
28 0.88961 7 15.09.2009 0.96730
29 0.88387 7 16.09.2009 0.62942
30 0.87821 7 17.09.2009 0.69590
31 0.62044 8 10.09.2009 0.91667
32 0.62319 8 11.09.2009 0.98894
33 0.62590 8 14.09.2009 0.96756
34 0.62857 8 15.09.2009 0.99710
35 0.62411 8 16.09.2009 0.79227
36 0.62676 8 17.09.2009 0.99935
Andre
Obsidian | Level 7
Eva

Here a tested result in 9.2.2
but Robert Allison woill surely present anything better
and perhaps resolving the appearance of mydate as tha name of the variable
HTH
Andre

[pre]
data mygraph;
informat mydate ddmmyy10.;
input
Obs q_aggregat mybyfield mydate wert ;
cards;
1 0.20930 2 10.09.2009 0.93528
2 0.21538 2 11.09.2009 0.98630
3 0.22137 2 14.09.2009 100.000
4 0.22727 2 15.09.2009 100.000
5 0.23308 2 16.09.2009 100.000
6 0.23881 2 17.09.2009 0.98230
7 0.33544 4 10.09.2009 0.98565
8 0.33962 4 11.09.2009 0.98898
9 0.33750 4 14.09.2009 0.88032
10 0.33540 4 15.09.2009 0.94600
11 0.33333 4 16.09.2009 0.73171
12 0.33129 4 17.09.2009 0.73291
13 0.77108 5 10.09.2009 100.000
14 0.77246 5 11.09.2009 0.98247
15 0.77381 5 14.09.2009 0.99673
16 0.77515 5 15.09.2009 0.99151
17 0.77059 5 16.09.2009 0.94867
18 0.77193 5 17.09.2009 100.000
19 0.51515 6 10.09.2009 0.96884
20 0.51807 6 11.09.2009 0.95833
21 0.52096 6 14.09.2009 0.95600
22 0.52381 6 15.09.2009 0.96962
23 0.52071 6 16.09.2009 0.93400
24 0.51765 6 17.09.2009 0.82052
25 0.89404 7 10.09.2009 0.45791
26 0.89474 7 11.09.2009 0.95247
27 0.88889 7 14.09.2009 0.87443
28 0.88961 7 15.09.2009 0.96730
29 0.88387 7 16.09.2009 0.62942
30 0.87821 7 17.09.2009 0.69590
31 0.62044 8 10.09.2009 0.91667
32 0.62319 8 11.09.2009 0.98894
33 0.62590 8 14.09.2009 0.96756
34 0.62857 8 15.09.2009 0.99710
35 0.62411 8 16.09.2009 0.79227
36 0.62676 8 17.09.2009 0.99935
;
run;


proc gbarline data=work.mygraph;
symbol1 value=dot height=5 interpol=join color=red width=2;
axis1 label=none order=(0 to 1 by 0.1);
axis2 label=none;
axis3 label=none order=(0 to 1 by 0.1);
legend1 mode=protect position=(middle center inside) shape=symbol(1 cm, 0.2 cm)
label=("quarterly" h=0.2 cm position=top );
legend2 mode=protect origin=(10,1.5)cm shape=bar(1 cm, 0.2 cm)
value=("sum of wert" h=0.2 cm);
format wert percent10.2 q_aggregat percent10.2;
by mybyfield;
bar mydate / sumvar = wert discrete raxis=axis1 maxis=axis2 ref= 0.95 cref = orange legend=legend2;
plot / sumvar = q_aggregat raxis=axis3 legend=legend1;
title "#byval(mybyfield)";
run;
quit;
[/pre]
GraphGuy
Meteorite | Level 14
Nicely done Andre!

Of course, since you've set everyone's expectations, I guess I now *have*
to try to provide a few small improvements 😉


options nobyline;
proc gbarline data=work.mygraph;
symbol1 value=dot height=2pct interpol=join color=red width=2;
axis1 label=none order=(0 to 1 by 0.2) minor=none offset=(0,0);
axis2 label=none value=(angle=90);
axis3 label=none order=(0 to 1 by 0.2) minor=none offset=(0,0);
legend1 position=(middle right) shape=symbol(1 cm, 0.2 cm)
label=none value=("quarterly");
legend2 position=(middle right) shape=bar(.15in,.15in)
label=none value=("sum of wert");
format wert q_aggregat percent10.0;
format mydate ddmmyy10.;
by mybyfield;
bar mydate / sumvar=wert discrete raxis=axis1 maxis=axis2 ref=0.95 lref=3 cref=orange legend=legend2;
plot / sumvar=q_aggregat raxis=axis3 legend=legend1;
title "Group: #byval(mybyfield)";
run;
quit;
Eva
Quartz | Level 8 Eva
Quartz | Level 8
Hello both of you,

thanx for your code. I tried it but unfortunately I don't get a legend.

I have SAS 9.1 and use the device activex. Maybe that's the reason I don't get a legend?

Best regards
Eva
GraphGuy
Meteorite | Level 14
Ahh! - I was using v9.2, and device=gif (and also the default device in dms windows sas).
Eva
Quartz | Level 8 Eva
Quartz | Level 8
device=gif doesn't work either

Is there another way to have a legend?

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