Data visualization with SAS programming

proc gbarline: legend?

Reply
Regular Contributor
Regular Contributor
Posts: 156

proc gbarline: legend?

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
Super Contributor
Posts: 273

Re: proc gbarline: legend?

Eva,
Show perhaps some code

Andre
Regular Contributor
Regular Contributor
Posts: 156

Re: proc gbarline: legend?

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;
SAS Employee
Posts: 967

Re: proc gbarline: legend?

Do you have any sample data you could provide, to go along with the sample code?
Regular Contributor
Regular Contributor
Posts: 156

Re: proc gbarline: legend?

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
Super Contributor
Posts: 273

Re: proc gbarline: legend?

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]
SAS Employee
Posts: 967

Re: proc gbarline: legend?

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;
Regular Contributor
Regular Contributor
Posts: 156

Re: proc gbarline: legend?

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
SAS Employee
Posts: 967

Re: proc gbarline: legend?

Ahh! - I was using v9.2, and device=gif (and also the default device in dms windows sas).
Regular Contributor
Regular Contributor
Posts: 156

Re: proc gbarline: legend?

device=gif doesn't work either

Is there another way to have a legend?
Ask a Question
Discussion stats
  • 9 replies
  • 455 views
  • 0 likes
  • 3 in conversation