I have tried to do this two ways. I want to plot two regression lines. I am not sure I have the correct sg procedure for I am not getting the two regression lines I want and I don't know why the legend is not positioning itself in top left corner in proc gplot. No errors are indicated. Any ideas? Thanks. MM
data simpson;
input week X Y percentLA;
percentRecall=X/Y;
datalines;
1 60 200 0
1 320 800 0
2 640 800 100
2 180 200 100
;
proc sgscatter data=simpson;
title 'Simpson Paradox';
plot percentRecall*percentLA / group=week;
run;
data simpson2;
input week percentRecall percentLA;
cards;
1 .3 0
2 .4 0
1 .8 100
2 .9 100
;
PROC GPLOT DATA=simpson2;
PLOT percentRecall*percentLA=week;
symbol1 value=dot i=r ci=orange;
symbol2 value=dot i=r ci=blue;
legend mode=protect down=2 position=(top left);
run; quit;
I might suggest spending time learning the SGPLOT as there are not any updates coming with the device based GPLOT procedure.
Generally you want to make sure that all the symbol, axis, legend and/or pattern statements are defined before the graphic procedure when using Gplot or Gchart.
It is a good idea to explicitly number your legends as well as symbols. Then you need to tell the procedure which legend to use.
This shows two plots with the legend:
symbol1 value=dot i=r ci=orange; symbol2 value=dot i=r ci=blue; legend1 mode=protect down=2 position=(top left); PROC GPLOT DATA=simpson2; PLOT percentRecall*percentLA=week / legend=legend1; run; quit;
Which will conflict with the y axis label but the legend does appear in the upper left.
At least for this data I might suggest placing it inside the graph.
A similar graph with SGPLOT:
proc sgplot data=simpson2; styleattrs datacontrastcolors=(orange blue); reg x=percentla y=percentrecall / group=week; keylegend /down=2 location=inside position=topleft ; run;
I might suggest spending time learning the SGPLOT as there are not any updates coming with the device based GPLOT procedure.
Generally you want to make sure that all the symbol, axis, legend and/or pattern statements are defined before the graphic procedure when using Gplot or Gchart.
It is a good idea to explicitly number your legends as well as symbols. Then you need to tell the procedure which legend to use.
This shows two plots with the legend:
symbol1 value=dot i=r ci=orange; symbol2 value=dot i=r ci=blue; legend1 mode=protect down=2 position=(top left); PROC GPLOT DATA=simpson2; PLOT percentRecall*percentLA=week / legend=legend1; run; quit;
Which will conflict with the y axis label but the legend does appear in the upper left.
At least for this data I might suggest placing it inside the graph.
A similar graph with SGPLOT:
proc sgplot data=simpson2; styleattrs datacontrastcolors=(orange blue); reg x=percentla y=percentrecall / group=week; keylegend /down=2 location=inside position=topleft ; run;
One of my problems with the sg series of graphics is that I'm never sure which one to use (sgplot, sgscatter, sgpanel). Is there a summary of what these procedures do somewhere? I sometimes get lost in the documentation. I need to post it somewhere where I can see it. Thank you for your reply.
Basically, it breaks down like this:
Hope this helps!
Dan
@MaryA_Marion wrote:
One of my problems with the sg series of graphics is that I'm never sure which one to use (sgplot, sgscatter, sgpanel). Is there a summary of what these procedures do somewhere? I sometimes get lost in the documentation. I need to post it somewhere where I can see it. Thank you for your reply.
Way back when, meaning SAS Version 6, I was given some tasks to do and two stack-feet of SAS manuals (stack foot is how high the pile measures when you lay the books on a table and stack them).
Look at procedure, try the sample programs, look at options, try code with my data. Wash, rinse, repeat until until the data matched the requirements for the graphing procedure and the output looked right.
Now days you don't have to worry about customizing the device drivers (Proc Gdevice) to get desired appearance which was pretty much a requirement with the Gplot/ Gchart procedures at the time if you did not have exactly the printer in the lists provided or wanted to use some of the less common options. I won't even go into the Graphic Stream File output learning curve.
Start at https://support.sas.com/en/knowledge-base/graph-samples-gallery.html for a whole bunch of complete examples of code and data. Look for a graph similar to what you want, or has elements that you want. Steal code freely to modify.
Thank you. Very helpful!
MM
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.