Date: Thu, 16 Apr 2009 09:38:40 -0400
Reply-To: msz03@albany.edu
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mike Zdeb <msz03@ALBANY.EDU>
Subject: Re: When is a LEGEND not a LEGEND?
Content-Type: text/plain;charset=iso-8859-1
hi Nat ... a summary
#1 Jim's code did not produce a legend
#2 Mike (me) suggested that no legend is produced since SAS/Graph sees that only one variable is involved
in each plot and decides that no legend is needed (overriding the Jim's use of the LEGEND= option)
Mike recreates the problem using SASHELP.CLASS and also gets NO LEGEND
proc sort data=sashelp.class out=class;
by sex;
run;
goptions reset=all;
symbol1 v=dot c=red i=rl w=2;
symbol2 v=dot c=blue i=rl w=2;
legend1 label=('Height') value=none;
legend2 label=('Weight') value=none;
proc gplot data=class;
plot height*age=1 / legend=legend1;
plot2 weight*age=2 / legend=legend2;
run;
quit;
#3 Robin High says that Mike's code using SASHELP.CLASS produces a LEGEND, but we discover that Robin is using V9.2 (an 'a ha' moment)
#4 data _null_ provides a V9.1 solution using Mike's code, replacing (the =1 and =2 with =sex) ... qualifying for another 'a ha' ...
proc gplot data=class;
plot weight*height=1 / legend=legend1;
plot2 age*height=2 / legend=legend2;
by sex;
run;
quit;
with ...
proc gplot data=class;
plot weight*height=sex / legend=legend1;
plot2 age*height=sex / legend=legend2;
by sex;
run;
QUIT;
meaning that Jim's code "should" work if he replaces ...
plot backedup*month=1 / vaxis=axis1 haxis=axis2 vzero legend=legend1;
plot2 retention*month=2 / vaxis=axis1 vzero legend=legend2;
by loc;
with ...
plot backedup*month=loc / vaxis=axis1 haxis=axis2 vzero legend=legend1;
plot2 retention*month=loc / vaxis=axis1 vzero legend=legend2;
by loc;
#5 Mike points out that this seems odd since in both cases SAS/Graph is only producing a plot with one variable, but
the use of the =<var> rather than =<constant> produces a LEGEND (a 'go figure' moment)
#6 so, Mike tries to figure out how to use the SASHELP.CLASS data to produce a plot with a LEGEND and NO BY VARIABLE, for example
the SASHELP.CLASS data using both genders in one plot ... the =<var> solution should still work, so he adds a variable to the data set
with the same value across all observations ...
proc sort data=sashelp.class out=class;
by sex;
run;
* add a new variable;
data class;
retain dummy 1;
set class;
run;
goptions reset=all;
symbol1 v=dot c=red i=rl w=2;
symbol2 v=dot c=blue i=rl w=2;
legend1 label=('Height') value=none;
legend2 label=('Weight') value=none;
* use the new variable as the 3rd variable in the plot ---> you get a LEGEND (though the 3rd variable has only one value);
proc gplot data=class;
plot height*age=dummy / legend=legend1;
plot2 weight*age=dummy / legend=legend2;
run;
quit;
* and to get back where this all started ... use a CONSTANT ---> you get a NO LEGEND;;
proc gplot data=class;
plot height*age=1 / legend=legend1;
plot2 weight*age=2 / legend=legend2;
run;
quit;
* same plot ---> you get a NO LEGEND;;
proc gplot data=class;
plot height*age / legend=legend1;
plot2 weight*age / legend=legend2;
run;
quit;
meaning that Jim's code should also work if he adds a new variable to his data that has the same value across all observations
and he uses the new variable in the plot statements ...
plot backedup*month=dummy / vaxis=axis1 haxis=axis2 vzero legend=legend1;
plot2 retention*month=dummy / vaxis=axis1 vzero legend=legend2;
by loc;
#7 moral ... use V9.2 and you get a legend ... use V9.1 and you have to 'play' a bit to get the legend but you can get one
ps waiting to hear if there really is an easier way in V9.1
--
Mike Zdeb
U@Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
> Jim
>
> Try the search function on the SAS tech support web site ( support.sas.com
> ). If there is a usage note on the topic, then they know about it. If you
> can't find it, then I suggest that you either call the
>
> 919-677-8008
>
> or use their email system for reporting problems
>
> http://support.sas.com/ctx/supportform/createForm
>
> This problem may be hard to find in the usage notes so a phone call may be
> the easiest approach.
>
>
>
> Nat Wooding
> Environmental Specialist III
> Dominion, Environmental Biology
> 4111 Castlewood Rd
> Richmond, VA 23234
> Phone:804-271-5313, Fax: 804-271-2977
>
>
>
> "Lane, Jim"
> <jim.lane@RBC.COM
> > To
> Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU
> Discussion" cc
> <SAS-L@LISTSERV.U
> GA.EDU> Subject
> Re: When is a LEGEND not a LEGEND?
>
> 04/16/2009 07:24
> AM
>
>
> Please respond to
> "Lane, Jim"
> <jim.lane@RBC.COM
> >
>
>
>
>
>
>
> Mike: so you're saying that my code will work in V9.2 but not in V9.1? If
> so that means, for all practical purposes, that I'm screwed. I wonder if
> SAS knows about this.
>
> -Jim
>
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Mike
> Zdeb
> Sent: 2009, April, 15 4:17 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: When is a LEGEND not a LEGEND?
>
> hi ... OK, another difference (I suspect) ...
>
> with your code, I still get no legend in V9.1
>
> but, I do get one with your code (and mine) in V9.2
>
> so ... hopefully you are running V9.2 so I understand what is going on here
>
> --
> Mike Zdeb
> U@Albany School of Public Health
> One University Place
> Rensselaer, New York 12144-3456
> P/518-402-6479 F/630-604-1475
>
>> Mike,
>>
>> My test code is almost identical to yours -- in this case I took
>> weight and age as the y (two vertical vars) and height as the x (1
>> horizontal) and it prints the respective legends at the bottom (as
>> written in the value option on each legend stmnt).
>>
>> goptions reset=all;
>>
>> axis1 label=none minor=none;
>> axis2 label=none order=50 to 75 by 5;
>>
>> SYMBOL1 i=none V=dot C=RED ;
>> SYMBOL2 i=none V=dot C=blue;
>>
>> legend1 label=none value=(h=1 'weight and height' ) ;
>> legend2 label=none value=(h=1 'age and height') ;
>>
>> title1 "title";
>>
>> proc sort data=sashelp.class out=cls; by sex;
>>
>> proc gplot data=cls;
>> plot weight*height=1 / vaxis=axis1 haxis=axis2 legend=legend1;
>> plot2 age*height=2 / vaxis=axis1 legend=legend2; by sex; run; QUIT;
>>
>> Robin High
>> UNMC
>>
>>
>>
>>
>>
>> "Mike Zdeb" <msz03@albany.edu>
>> 04/15/2009 02:37 PM
>> Please respond to
>> msz03@albany.edu
>>
>>
>> To
>> SAS-L@LISTSERV.UGA.EDU
>> cc
>>
>> Subject
>> Re: [SAS-L] When is a LEGEND not a LEGEND?
>>
>>
>>
>>
>>
>>
>> hi ... I think that the problem is that each plot only comprises one
>> Y-variable
>>
>> when SAS sees only one Y-variable in a plot, it decides on its own
>> that no legend is needed
>>
>> for example ... no legend in this either ...
>>
>> proc sort data=sashelp.class out=class; by sex; run;
>>
>> goptions reset=all;
>>
>> symbol1 v=dot c=red i=rl w=2;
>> symbol2 v=dot c=blue i=rl w=2;
>>
>> legend1 label=('LEGEND 1');
>> legend2 label=('LEGEND 2');
>>
>> proc gplot data=class;
>> plot height*age=1 / legend=legend1;
>> plot2 weight*age=2 / legend=legend2;
>> by sex;
>> run;
>> quit;
>>
>> so, Robin: could you post the code that gives a legend with only one
>> Y-variable ... thanks
>>
>>
>> meantime, you could "PUNT" and use another method to tell others what
>> the chart symbols represent ...
>>
>> goptions reset=all;
>>
>> symbol1 v=dot c=red i=rl;
>> symbol2 v=dot c=blue i=rl;
>>
>> axis1 label=(a=90 'HEIGHT (RED)');
>> axis2 label=(a=90 'WEIGHT (BLUE)');
>>
>> proc gplot data=class;
>> plot height*age=1 / vaxis=axis1;
>> plot2 weight*age=2 / vaxis=axis2;
>> by sex;
>> run;
>> quit;
>>
>> --
>> Mike Zdeb
>> U@Albany School of Public Health
>> One University Place
>> Rensselaer, New York 12144-3456
>> P/518-402-6479 F/630-604-1475
>>
>>> Jim,
>>>
>>> Not sure what the problem could be. I tried your code with a similar
>>> dataset including the BY variable with graphs sent to a pdf file and
>>> the legend appeared as expected. You might try repositioning the
>>> legend with something like:
>>>
>>> legend1 mode=share label=none value=(h=1 'Backed Up' ) position=(top
>>> right inside) ;
>>> legend2 mode=share label=none value=(h=1 'Days Retained') position=(
>>> middle right inside) ;
>>>
>>> and check if it is still not there. Also could reposition the axes
>> perhaps
>>>
>>> Robin High
>>> UNMC
>>>
>>>
>>>
>>>
>>>
>>> "Lane, Jim" <jim.lane@RBC.COM>
>>> Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
>>> 04/15/2009 01:04 PM
>>> Please respond to
>>> "Lane, Jim" <jim.lane@RBC.COM>
>>>
>>>
>>> To
>>> SAS-L@LISTSERV.UGA.EDU
>>> cc
>>>
>>> Subject
>>> When is a LEGEND not a LEGEND?
>>>
>>>
>>>
>>>
>>>
>>>
>>> Apparently a LEGEND isn't a LEGEND when it isn't anything at all and
>>> it's giving me fits! My code looks like this:
>>>
>>> ods pdf file="output.pdf";
>>> options orientation=landscape nodate; GOPTIONS DEV=SASPRTC
>>> ftext="simplex";
>>> axis1 label=none minor=none;
>>> axis2 label=none order=('01jul2008'd to '01mar2009'd by month);
>>> SYMBOL1 V=dot C=RED i=j;
>>> SYMBOL2 V=dot C=blue i=j;
>>> legend1 label=none value=(h=0.75 'Backed Up' ) ;
>>> legend2 label=none value=(h=0.75 'Days Retained') ;
>>> title1 "title";
>>> proc gplot data=s;
>>> plot backedup*month=1 / vaxis=axis1 haxis=axis2 vzero
>>> legend=legend1;
>>> plot2 retention*month=2 / vaxis=axis1 vzero legend=legend2; by loc;
>>> run; QUIT; ODS pdf CLOSE; GOPTIONS RESET=All;
>>>
>>> When I run this I get a perfectly satisfactory graph with no legends
>>> at all and nothing in the log about legends one way or the other.
>>> It's as if SAS never even saw my legend statements or options. What
>>> am I doing wrong here?
>>>
>>> Jim Lane
>>> Capacity Planner
>>> RBC Financial Group
>>> 315 Front St W
>>> 6th Floor - H14
>>> Toronto, Ontario CANADA
>>> M5V 3A4
>>> 416-348-6024
>>>
>>> Display of superior knowledge is as great a vulgarity as display of
>>> superior wealth - greater indeed, inasmuch as knowledge should tend
>>> more definitely than wealth towards discretion and good manners.
>>>
>>> - H. W. Fowler, Modern English Usage
>>>
>>>
>>> _____________________________________________________________________
>>> __
>>>
>>> This e-mail may be privileged and/or confidential, and the sender
>>> does
>> not
>>> waive any related rights and obligations.
>>> Any distribution, use or copying of this e-mail or the information it
>>> contains by other than an intended recipient is unauthorized.
>>> If you received this e-mail in error, please advise me (by return
>>> e-mail or otherwise) immediately.
>>>
>>> Ce courrier électronique est confidentiel et protégé. L'expéditeur ne
>>> renonce pas aux droits et obligations qui s'y rapportent.
>>> Toute diffusion, utilisation ou copie de ce message ou des
>> renseignements
>>> qu'il contient par une personne autre que le (les) destinataire(s)
>>> désigné(s) est interdite.
>>> Si vous recevez ce courrier électronique par erreur, veuillez m'en
>> aviser
>>> immédiatement, par retour de courrier électronique ou par un autre
>> moyen.
>>>
>>
>>
>>
> _______________________________________________________________________
>
> This e-mail may be privileged and/or confidential, and the sender does not
> waive any related rights and obligations.
> Any distribution, use or copying of this e-mail or the information it
> contains by other than an intended recipient is unauthorized.
> If you received this e-mail in error, please advise me (by return e-mail or
> otherwise) immediately.
>
> Ce courrier électronique est confidentiel et protégé. L'expéditeur ne
> renonce pas aux droits et obligations qui s'y rapportent.
> Toute diffusion, utilisation ou copie de ce message ou des renseignements
> qu'il contient par une personne autre que le (les) destinataire(s)
> désigné(s) est interdite.
> Si vous recevez ce courrier électronique par erreur, veuillez m'en aviser
> immédiatement, par retour de courrier électronique ou par un autre moyen.
>
>
> CONFIDENTIALITY NOTICE: This electronic message contains
> information which may be legally confidential and or privileged and
> does not in any case represent a firm ENERGY COMMODITY bid or offer
> relating thereto which binds the sender without an additional
> express written confirmation to that effect. The information is
> intended solely for the individual or entity named above and access
> by anyone else is unauthorized. If you are not the intended
> recipient, any disclosure, copying, distribution, or use of the
> contents of this information is prohibited and may be unlawful. If
> you have received this electronic transmission in error, please
> reply immediately to the sender that you have received the message
> in error, and delete it. Thank you.
>